#include #include #include #include #include #include #include using namespace std; const int N=105; int n,x,y,a[N][2],ans,fa[N],T,f1,f2; int get(int x) { if (x==fa[x]) return x; else return fa[x]=get(fa[x]); } int main() { cin>>T; while (T--) { cin>>n; ans=0; for (int i=1;i<=n+1;i++) scanf("%d%d",&a[i][0],&a[i][1]); for (int i=0;i<=n;i++) for (int j=i+1;j<=n+1;j++) { for (int k=1;k<=n;k++) fa[k]=k; for (int k=1;k<=n+1;k++) if (k!=i&&k!=j) { f1=get(a[k][0]); f2=get(a[k][1]); fa[f1]=f2; } bool o=1; for (int k=1;k<=n;k++) if (get(k)!=get(1)) o=0; ans+=o; } cout<