#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<vector<int>> g;
int n;
int leaves = 0;
int fll;
int lev[200005];
int bb[200005];
int bud;
void dfs(int nn, int pp) {
  int isLeaf = 1;
  int isBud = 0;
  for (auto u : g[nn]) {
    if (u == pp) continue;
    dfs(u, nn);
    if (lev[u] == 1) {
      isBud = 1;
      isLeaf = 0;
    }
  }
  lev[nn] = isLeaf;
  if (isBud and nn != 1) {
    bud++;
  }
  if (isBud and nn == 1) fll = 1;
}
void solve() {
  cin >> n;
  g.clear();
  g.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  leaves = 0;
  fll = 0;
  bud = 0;
  int ans;
  dfs(1, -1);
  ans = n - 2 * bud - 1;
  if (fll == 0) ans += 1;
  cout << ans << '\n';
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long tc = 1;
  cin >> tc;
  for (long long i = 1; i <= tc; i++) {
    solve();
  }
}
