#include<bits/stdc++.h>
using namespace std;
const int N=20;
int f[N],n;
struct node{int x,y;
}p[N],q[N];
int check(int i,int j){if (max(q[i].x,p[i].x)<min(q[j].x,p[j].x)||max(q[i].y,p[i].y)<min(q[j].y,p[j].y)||max(q[j].x,p[j].x)<min(q[i].x,p[i].x)||max(q[j].y,p[j].y)<min(q[i].y,p[i].y)) return 0;int u=(p[j].x-p[i].x)*(q[i].y-p[i].y)-(q[i].x-p[i].x)*(p[j].y-p[i].y);int v=(q[j].x-p[i].x)*(q[i].y-p[i].y)-(q[i].x-p[i].x)*(q[j].y-p[i].y);int w=(q[i].x-p[j].x)*(q[j].y-p[j].y)-(q[j].x-p[j].x)*(q[i].y-p[j].y);int z=(p[i].x-p[j].x)*(q[j].y-p[j].y)-(q[j].x-p[j].x)*(p[i].y-p[j].y);return (u*v<=0&&w*z<=0);
}
int get(int x){return x==f[x]?x:f[x]=get(f[x]);
}
void union_set(){for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++) if(check(i,j)) f[get(i)]=get(j);}
}
int main(){while(cin>>n){for(int i=1;i<=n;i++) f[i]=i;for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y>>q[i].x>>q[i].y;union_set();int a,b;while(cin>>a>>b,a||b){if(get(a)==get(b)) cout<<"CONNECTED"<<endl;else cout<<"NOT CONNECTED"<<endl;}}return 0;
}