#include #include #include #include #include #include #include #include #include #include #define maxn 110 #define fr first #define sc second #define mp make_pair #define pb push_back #define son e[i].t #define pow POW #define clear(x) memset(x, 0, sizeof(x)) typedef long long ll; using namespace std; void gn(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9'){ if (ch == '-') f = -1; ch = getchar(); }while (ch >= '0' && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); }x *= f; } int T, u, v, fa[maxn], n; int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; } int x[maxn], y[maxn]; bool b[maxn]; bool merge(int x, int y) { x = find(x); y = find(y); if (x == y) return 0; fa[x] = y; return 1; } bool check() { int tot = n; clear(fa); for (int i = 1; i <= n + 1; ++ i) if (! b[i]){ tot -= merge(x[i], y[i]); } return tot == 1; } void solve() { gn(n); for (int i = 1; i <= n + 1; ++ i){ gn(x[i]); gn(y[i]); } int ans = 0; clear(b); for (int i = 1; i <= n + 1; ++ i){ b[i] = 1; if (check()) ++ ans; b[i] = 0; } for (int i = 1; i <= n + 1; ++ i) for (int j = i + 1; j <= n + 1; ++ j){ b[i] = b[j] = 1; if (check()) ++ ans; b[i] = b[j] = 0; } printf("%d\n", ans); } int main() { gn(T); while (T --) solve(); }