#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); int t; cin>>t; while(t--) { ll n; cin>>n; int m=n-1; vector<vector<int>>adj(n); vector<int>indegree(n,0); while(m--) { int x;int y; cin>>x>>y; x--; y--; adj[x].push_back(y); adj[y].push_back(x); indegree[x]++; indegree[y]++; } int mx1=0; int mx2=0; if(adj[0].size()==0) { cout<<0<<endl; continue; } if(adj[0].size()==1) { cout<<n-2<<endl; continue; } // cout<<indegree[adj[0][1]]<<endl; int mi=min(indegree[adj[0][0]],indegree[adj[0][1]]); int ans=mi+1+1; cout<<n-ans<<endl; } }