#include <bits/stdc++.h>

using namespace std;

int t, n, flag, up[200002];
vector<int>G[200002];

bool dfs (int x, int p, int k) {
  if (x > 1 && G[x].size() == 1) {
    up[x] = 0;
    return 1;
  }
  up[x] = 1e9;
  int cnt = 0;
  int mn = 1e9;
  for (auto it : G[x])
    if (it != p) {
      int check = dfs(it, x, k);
      if (!check)
        return 0;
      mn = min(up[it] + 1, mn);
      if (up[it] + 2 <= k)
        continue;
      cnt++;
      up[x] = up[it] + 1;
      if (x == 1)
        if (up[it] + 1 > k)
          {return 0;}
    }
  if (cnt > 1) {
    return 0;
  }
  if (!cnt)
    up[x] = mn;
  return 1;
}

void reset (int n) {
  for (int i = 1; i <= n; i++)
    G[i].clear();
}

void solve () {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int lim = 0;
  while ((1 << lim) <= n)
    lim++;
  int ans = 0;
  for (int pas = (1 << lim); pas; (pas >>= 1)) {
    if (ans + pas <= n && !dfs(1, 0, ans + pas))
      ans += pas;
  }
  reset(n);
  cout << ans + 1 << "\n";
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
