#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll __int64 int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - '0' ; while( ( ch = getchar() ) >= '0' && ch <= '9' ) res = res * 10 + ( ch - '0' ) ; return res ; } struct point { int x,y; }a[110]; int father[110]; void init(int y) { for(int i=1;i<=y;i++) father[i]=i; } int findfa(int x) { if(x!=father[x]) return father[x]=findfa(father[x]); return x; } int check(int y) { int hehe=findfa(1); for(int i=2;i<=y;i++) if(findfa(i)!=hehe) return 0; return 1; } void unionn(int x,int y) { int xx=findfa(x); int yy=findfa(y); if(xx!=yy) father[xx]=yy; } int main() { int x,y,z,i,t; scanf("%d",&x); while(x--) { scanf("%d",&y); for(i=0;i<=y;i++) scanf("%d%d",&a[i].x,&a[i].y); int ans=0; for(i=0;i<=y;i++) { init(y); for(t=0;t<=y;t++) { if(i!=t) unionn(a[t].x,a[t].y); } if(check(y)) ans++; } for(i=0;i<=y;i++) for(t=i+1;t<=y;t++) { init(y); for(int j=0;j<=y;j++) { if(j!=i&&j!=t) unionn(a[j].x,a[j].y); } if(check(y)) ans++; } printf("%d\n",ans); } return 0; }