#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int range(double p,double q,double r){
  return (q<r?q:r)<=p&&p<=(r>q?r:q);
}
int rangea(double p,double q,double r){
  if(q*r<0&&fabs(q)+fabs(r)>M_PI){
    p+=2*M_PI*(p<0);
    q+=2*M_PI*(q<0);
    r+=2*M_PI*(r<0);
  }
  return range(p,q,r);
}
int pit(int x0,int y0,int x1,int y1,int x2,int y2,int px,int py){
  if(1&&
     rangea(atan2(y0-py,x0-px),atan2(y0-y1,x0-x1),atan2(y0-y2,x0-x2))&&
     rangea(atan2(y1-py,x1-px),atan2(y1-y0,x1-x0),atan2(y1-y2,x1-x2)))
    return 1;
  return 0;
}
int main(){
  int h,i,j,k;
  int a[100],b[100],c[100],x[100][4],y[100][4],m,n;
  while(cin>>n&&n){
    memset(c,0,sizeof(c));
    for(h=0;h<n;h++){
      cin>>m;
      for(i=0;i<m;i++){
	for(j=0;j<4;j++)
	  cin>>x[i][j]>>y[i][j];
	a[i]=i;
	for(j=0;j<i;j++){
	  if(a[i]!=a[j]){
	    for(k=0;k<4;k++){
	      if(0||
		 pit(x[i][0],y[i][0],x[i][1],y[i][1],x[i][2],y[i][2],x[j][k],y[j][k])||
		 pit(x[i][0],y[i][0],x[i][2],y[i][2],x[i][3],y[i][3],x[j][k],y[j][k])||
		 pit(x[j][0],y[j][0],x[j][1],y[j][1],x[j][2],y[j][2],x[i][k],y[i][k])||
		 pit(x[j][0],y[j][0],x[j][2],y[j][2],x[j][3],y[j][3],x[i][k],y[i][k]))
		break;
	    }
	    if(k!=4){
	      for(k=0;k<i;k++){
		if(k!=j&&a[k]==a[j])
		  a[k]=a[i];
	      }
	      a[j]=a[i];
	    }
	  }
	}
      }
      memset(b,0,sizeof(b));
      for(i=0;i<m;i++){
	if(b[a[i]]==0){
	  b[a[i]]=1;
	  c[h]++;
	}
      }
      cout<<c[h]<<endl;
    }
  }
  return 0;
}