/********************************************* Problem : HDU Bestcoder Author : NMfloat InkTime (c) NM . All Rights Reserved . ********************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,a,b) for(int i = (a) ; i <= (b) ; i ++) //遍历 #define rrep(i,a,b) for(int i = (b) ; i >= (a) ; i --) //反向遍历 #define repS(it,p) for(auto it = p.begin() ; it != p.end() ; it ++) //遍历一个STL容器 #define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next) //遍历u所连接的点 #define cls(a,x) memset(a,x,sizeof(a)) #define eps 1e-8 using namespace std; const int MOD = 1e9+7; const int INF = 0x3f3f3f3f; const int MAXN = 105; const int MAXE = 205; typedef long long LL; typedef unsigned long long ULL; struct Edge { //记录边 int to; Edge * next; }E[MAXE],*EE; struct Gragh { //记录图的结点 Edge * first; }G[MAXN]; int T; int n,m,k; void addedge(int u,int v) { //加边,双向边 EE->to = v ; EE -> next = G[u].first ; G[u].first = EE ++; EE->to = u ; EE -> next = G[v].first ; G[v].first = EE ++; } void init() { EE = E; cls(G,0); } int fx[] = {0,1,-1,0,0}; int fy[] = {0,0,0,-1,1}; int x[105]; int y[105]; bool vis[105]; void input() { scanf("%d",&n); rep(i,1,n+1) { scanf("%d %d",&x[i],&y[i]); } } void dfs(int u) { repE(p,u) { int v = p->to; if(!vis[v]) { vis[v] = true; dfs(v); } } } void solve() { int cnt = 0; rep(i,1,n+1) { //拆掉单边 cls(vis,0); init(); rep(j,1,n+1) { if(j == i) continue; addedge(x[j],y[j]); } vis[1] = 1; dfs(1); int ok = 1; rep(i,1,n) { if(!vis[i]) {ok = 0 ; break;} } cnt += ok; } rep(i,1,n+1) { //拆掉两条边 rep(k,i+1,n+1) { cls(vis,0); init(); rep(j,1,n+1) { if(j == i || j == k) continue; addedge(x[j],y[j]); } vis[1] = 1; dfs(1); int ok = 1; rep(i,1,n) { if(!vis[i]) {ok = 0 ; break;} } cnt += ok; } } printf("%d\n",cnt); } int main(void) { // freopen("a.in","r",stdin); scanf("%d",&T); while(T--) { input(); solve(); } return 0; }