#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> e[maxn];
int vis[maxn];
int ans;
int n;
int x, y;
void dfs(int now) {
  vis[now] = 1;
  int flag = 0;
  for (auto i : e[now]) {
    if (vis[i] == 0) {
      dfs(i);
      flag = flag | vis[i];
    }
  }
  if (flag == 0)
    vis[now] = 1;
  else if (flag == 1)
    vis[now] = 2;
  else if (flag == 2)
    vis[now] = 1;
  else if (flag == 3)
    vis[now] = 2;
  else if (flag == 7)
    vis[now] = 7;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) vector<int>().swap(e[i]);
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      e[x].push_back(y);
      e[y].push_back(x);
    }
    for (int i = 1; i <= n; i++) vis[i] = 0;
    ans = 0;
    dfs(1);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 1)
        ans++;
      else if (vis[i] == 2)
        ans--;
    }
    cout << ans + (vis[1] == 2) << endl;
  }
}
