#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int n, m;
vector<int> edge[MAXN];
int f[MAXN];
int ans;
void dfs(int u, int fa) {
  f[u] = 1;
  int mx = 0, sz = 0, p;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == fa) continue;
    dfs(v, u);
    if (f[v] > mx) {
      mx = f[v];
      p = v;
    }
    sz++;
  }
  if (sz != 0) {
    f[u] = mx + sz;
    ans = max(ans, f[u]);
    mx = 0;
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i];
      if (v == fa || v == p) continue;
      mx = max(mx, f[v]);
    }
    if (u == 1) {
      ans = max(ans, f[u] + mx - 1);
    } else {
      ans = max(ans, f[u] + mx);
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      edge[a].push_back(b);
      edge[b].push_back(a);
    }
    ans = 1;
    dfs(1, 0);
    printf("%d\n", ans);
  }
  return 0;
}
