#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
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBmIGZ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