#include <bits/stdc++.h>
using namespace std;
long long dp[300005];
vector<long long> g[300005];
long long ans = 1;
long long subs[300005];
long long f[300005][2];
void dfs(long long s, long long p) {
  dp[s] = 0;
  long long mx1 = 0;
  long long mx2 = 0;
  long long cnt = 0;
  for (auto it : g[s]) {
    if (it != p) {
      dfs(it, s);
      if (mx1 < dp[it]) {
        mx2 = mx1;
        mx1 = dp[it];
      } else if (mx2 < dp[it])
        mx2 = dp[it];
      cnt++;
    }
  }
  f[s][0] = mx1;
  f[s][1] = mx2;
  subs[s] = cnt;
  dp[s] += mx1 + cnt;
}
void ans_dfs(long long s, long long p) {
  for (auto it : g[s]) {
    if (it != p) ans_dfs(it, s);
  }
  if (s == p) {
    ans = max(ans, 1 + dp[s] + f[s][1]);
    return;
  }
  long long y = f[p][0];
  if (y == dp[s]) y = f[p][1];
  long long z = max(y, f[s][1]);
  ans = max(ans, 1 + dp[s] + z + 1);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      dp[i] = 0;
      g[i].clear();
    }
    for (long long i = 0; i < n - 1; i++) {
      long long a, b;
      cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    ans = 1;
    dfs(1, 1);
    ans_dfs(1, 1);
    cout << ans << "\n";
  }
  return 0;
}
