#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define b back
#define cout(x) cout << x << endl
#define lb long double
#define soa(arr, n) sort(arr,arr+n)
#define inputVector(v, n) for(int i = 0; i < n; i++) cin >> v[i]
#define sov(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define pl pair<ll, ll>
#define all(a)    a.begin(), a.end()
#define vpp vector<pair<ll, ll>>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int  ll;
ll P = 1e9 + 7;
vector<ll> adj[300001];
priority_queue<ll,  vector<ll>, greater<ll>> pq;
ll isLeaf(vector<ll> & vis, ll u) {
    vis[u] = 1;
    ll ans = 1;
    ll leaf = 0;
    ll vv = 0;
    for(auto v: adj[u]) {
        if(!vis[v]) {
            leaf = 1;
            ans &= isLeaf(vis, v);
            vv += 1;
        }
    }
    if(ans && vv) {
        pq.push(vv);
    }
    return !leaf;
}

void solve() {
    ll  n, q, k, l, x, y, m;
    cin >> n;
    for(ll i = 1; i <= n; i ++) {
        adj[i].clear();
    }
    
    for(ll i = 1; i < n; i ++) {
        cin >> x >> y;
        adj[x].pb(y);
    }
    vector<ll> vis(n + 1);
    isLeaf(vis, 1);
    while(pq.size() > 1) {
        auto u = pq.top();
        pq.pop();
        auto v = pq.top();
        pq.pop();
        pq.push(u + v -1);
    }
    if(pq.size() > 0) {
    cout << pq.top() << endl;
    pq.pop();
    }
    else {
        cout << 1 << endl;
    }
    
}


int main() {
    ll t=1,i=1;
    fastIo;
    cin >> t;
    while(t--) {
        // cout << "Case #" << i << ": ";
        solve();
        i++;
    }
    return 0;
}
// 2 3 5 6 7 10 11 13 15 17 19 21 22 23 25 26 29 30
