#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> G[N];
int n, p[N], deg[N], del[N], cnt[N];
void dfs(int u, int r) {
  deg[u] = del[u] = cnt[u] = 0;
  for (int v : G[u])
    if (v != r) p[v] = u, cnt[u]++, dfs(v, u);
  if (cnt[u]) deg[p[u]]++;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) G[i].clear();
    for (int i = 1, u, v; i < n; ++i) {
      cin >> u >> v;
      G[u].emplace_back(v), G[v].emplace_back(u);
    }
    dfs(1, 0);
    queue<int> q;
    for (int i = 2; i <= n; ++i)
      if (cnt[i] > 0 && deg[i] == 0) q.push(i), del[i] = 1;
    int res = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      res += cnt[u] - 1;
      int v = p[u];
      deg[v]--;
      cnt[v]--;
      if (v == 1) continue;
      if (cnt[v] == 0) {
        int r = p[v];
        deg[r]--;
        if (r > 1 && deg[r] == 0 && !del[r]) {
          del[r] = 1;
          q.push(r);
        }
      } else if (deg[v] == 0 && !del[v]) {
        del[v] = 1;
        q.push(v);
      }
    }
    for (int i = 1; i <= n; ++i)
      if (!del[i] && !del[p[i]] && !cnt[i]) res++;
    cout << res << "\n";
  }
  return 0;
}
