//2535437 2010-06-12 00:42:04 Accepted 1558 109MS 256K 2695 B C++ T&T
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
struct point{
double x,y;
};
struct sdl{
point s1;
point s2;
}xd[1002];
int p[1002];
int deep[1002];
int count[1002];
//int count;
double max(double a,double b)
{
return a > b ? a : b;
}
double min(double a,double b)
{
return a < b ? a : b;
}
double chacheng(point p0,point p1,point p2)
{
return (p1.x - p0.x)*(p2.y - p0.y)-(p2.x- p0.x)*(p1.y - p0.y);
}
bool iscross(point a,point b,point c,point d)
{
if(max(a.x,b.x) >= min(c.x,d.x) && max(a.y,b.y) >= min(c.y,d.y) && max(c.x,d.x) >= min(a.x,b.x) && max(c.y,d.y) >= min(a.y,b.y))
{//最小矩陣測試
if(chacheng(a,c,b)*chacheng(a,b,d) >= 0 && chacheng(c,a,d)*chacheng(c,d,b) >= 0)
{
return true;
}
}// 這裏的max沒有大於等於錯了一個晚上
return false;
}
int find(int x)
{
int r,j;
r = x;
while(r != p[r])
{
j = r;
r = p[r];
p[j] = p[r]; //壓縮路徑
}
return r;
}
void merge(int x,int y)
{
int fx,fy;
fx = find(x);
fy = find(y);
if(fx != fy)
{
if(deep[fx] > deep[fy])
{
p[fy] = fx;
count[fx] += count[fy]; //將深度小的樹添加到深度大的樹
}
else
{
p[fx] = fy;
count[fy] += count[fx];
if(deep[fx] == deep[fy])
{
deep[fy]++; //兩棵深度相同的樹向並改變深度
}
}
}
}
int main()
{
int t,n,k,i,res,j,b;
point s1,s2;
char choice;
scanf("%d",&t);
while(t--)
{
//memset(count,1,sizeof(count));
b = 1;
//count =
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
p[i]= i;
deep[i] = 1;
count[i] = 1;
}
for(i = 1; i <= n; i++)
{
scanf("%s",&choice);
if(choice == 'P')
{
//p[b] = b;
//count[b] = 1;
//deep[b] = b;
scanf("%lf%lf%lf%lf",&xd[b].s1.x,&xd[b].s1.y,&xd[b].s2.x,&xd[b].s2.y);
if(b > 1)
{
for(j = 1; j < b; j++)
{
if(iscross(xd[b].s1,xd[b].s2,xd[j].s1,xd[j].s2))
{
merge(j,b);
}
}
}
b++;
}
else
{
scanf("%d",&k);
res = find(k);
printf("%d/n",count[res]);
}
}
if(t)
printf("/n");
}
}