#include <bits/stdc++.h>
using namespace std;
long long maxn = 2 * 1e5 + 10;
long long n;
vector<vector<long long>> edges;
vector<long long> b, is_bud, l;
long long buds = 0, all_leaves = 0, leaves0 = 0;
;
void dfs(long long v, long long p) {
  long long gch = 0, lsum = 0;
  for (long long to : edges[v]) {
    if (to == p) continue;
    dfs(to, v);
    lsum += l[to];
    if (is_bud[to]) continue;
    if (edges[to].size() - b[to] == 1) {
      gch++;
    }
  }
  if (v != 0 && edges[v].size() - 1 - b[v] == gch && gch > 0) {
    buds++;
    b[p]++;
    is_bud[v] = 1;
    if (p != 0 && edges[p].size() - b[p] == 1) all_leaves++;
  }
}
long long solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    edges[i].clear();
    b[i] = 0;
    is_bud[i] = 0;
    l[i] = 0;
  }
  buds = 0;
  set<long long> neib;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    if (u > v) swap(u, v);
    if (u == 0) neib.insert(v);
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  all_leaves = 0, leaves0 = 0;
  for (long long i = 1; i < n; i++) {
    l[i] = (edges[i].size() == 1);
    all_leaves += (edges[i].size() == 1);
  }
  dfs(0, -1);
  for (long long i = 1; i < n; i++) {
    if (edges[i].size() - b[i] == 1 && neib.find(i) != neib.end()) leaves0++;
  }
  if (leaves0 > 0) {
    cout << all_leaves - buds << "\n";
  } else {
    cout << all_leaves - max(0ll, buds - 1) << "\n";
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  edges.resize(maxn);
  b.resize(maxn);
  is_bud.resize(maxn);
  l.resize(maxn);
  long long tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}
