#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
struct line{
int x1,x2,y1,y2;
};
line p[15];
int n;
int f[15],cnt;
bool flag[15];
//判断两条线段是否直接相交(有公共点)
bool judge(line a,line b){
int temp=(a.x1-a.x2)*(b.y1-b.y2)-(a.y1-a.y2)*(b.x1-b.x2);
if(temp==0){//平行
int temp_1=(a.x1-b.x1)*(a.y2-b.y1)-(a.y1-b.y1)*(a.x2-b.x1);
if(temp_1==0){//共线(也分有无公共点)
if(a.x1!=a.x2&&(max(a.x1,a.x2)<min(b.x1,b.x2)||min(a.x1,a.x2)>max(b.x1,b.x2)))
return false;
else if(a.x1==a.x2&&(max(a.y1,a.y2)<min(b.y1,b.y2)||min(a.y1,a.y2)>max(b.y1,b.y2)))
return false;
else return true;
}
else return false;//平行不共线必无公共点
}
//求交点
int x1=a.x1,x2=a.x2,y1=a.y1,y2=a.y2;
int x3=b.x1,x4=b.x2,y3=b.y1,y4=b.y2;
double a1=y1-y2;
double b1=x2-x1;
double c1=x1*y2-x2*y1;
double a2=y3-y4;
double b2=x4-x3;
double c2=x3*y4-x4*y3;
double x0=(c2*b1-c1*b2)/(a1*b2-a2*b1);
double y0=(c1*a2-c2*a1)/(a1*b2-a2*b1);
//判断交点是否同时在两条线段上
if(x0<(double)max(min(x1,x2),min(x3,x4))||x0>(double)min(max(x1,x2),max(x3,x4))||y0<(double)max(min(y1,y2),min(y3,y4))||y0>(double)min(max(y1,y2),max(y3,y4)))
return false;
return true;
}
//染色法dfs
void dfs(int x){
flag[x]=true;
f[x]=cnt;//集合标号
for(int i=1;i<=n;i++){
if(!flag[i]&&judge(p[x],p[i])){
dfs(i);
}
}
return ;
}
//集合分组
void init(){
cnt=1;//表示集合数
memset(flag,false,sizeof(flag));
for(int i=1;i<=n;i++){
if(flag[i])continue;
dfs(i);
cnt++;
}
}
int main(){
int x,y;
while(cin>>n&&n){
for(int i=1;i<=15;i++)f[i]=0;
for(int i=1;i<=n;i++){
cin>>p[i].x1>>p[i].y1>>p[i].x2>>p[i].y2;
}
init();
while(cin>>x>>y&&(x||y)){
if(f[x]==f[y]){//属于同一个集合
cout<<"CONNECTED"<<endl;
}
else cout<<"NOT CONNECTED"<<endl;
}
}
return 0;
}
// /\ | / |**、
// / \ | / | \
// / \ |/ | / _____ ____ | /
// /------\ |\ |__/ / \ \ /\ / / \ | /
// / \ | \ | / \ \ / \ / /______\ |/
// / \ | \ | \ / \ / \ / \ |
// / \ | \ | \_____/ \/ \/ \_____ |
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//