#include #include #include using namespace std; typedef pair P; vector

edge; int par[105], rk[105]; void init(int n) { for (int i = 1; i <= n; ++i) { par[i] = i; rk[i] = 0; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rk[x] < rk[y]) par[x] = y; else { par[y] = x; if (rk[x] == rk[y]) ++rk[x]; } } bool same(int x, int y) { return find(x) == find(y); } bool judge(int n, int a, int b) { init(n); for (int i = 0; i <= n; ++i) if (i != a && i != b) unite(edge[i].first, edge[i].second); for (int i = 1; i < n; ++i) if (!same(i, i + 1)) return false; return true; } int main() { int t, n, u, v; scanf("%d", &t); while (t--) { scanf("%d", &n); edge.clear(); for (int i = 0; i <= n; ++i) { scanf("%d %d", &u, &v); edge.push_back(P(u, v)); } int ans = 0; for (int i = 0; i <= n; ++i) if (judge(n, i, i)) ++ans; for (int i = 0; i < n; ++i) for (int j = i + 1; j <= n; ++j) if (judge(n, i, j)) ++ans; printf("%d\n", ans); } return 0; }