#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
vector<int> ve[N];
int d[N], dep[N], root, ans;
void dfs(int u, int f) {
  dep[u] = dep[f] + d[u];
  for (int v : ve[u]) {
    if (v == f) continue;
    dfs(v, u);
  }
  if (dep[u] > dep[root]) root = u;
  ans = max(dep[u], ans);
}
int main() {
  int q, n;
  scanf("%d", &q);
  while (q--) {
    ans = 0, root = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) ve[i].clear(), d[i] = -1, dep[i] = 0;
    for (int i = 1, a, b; i < n; i++) {
      scanf("%d %d", &a, &b);
      ve[a].push_back(b);
      ve[b].push_back(a);
      d[b]++, d[a]++;
    }
    dfs(1, 0);
    dfs(root, 0);
    printf("%d\n", min(ans + 2, n));
  }
}
