#include <bits/stdc++.h>
using namespace std;
int n, m, deg[300030], ans, rt, cnt, head[300030], T;
struct E {
  int to, nxt;
} edge[300030 << 1];
inline void add(int u, int v) {
  edge[++cnt] = (E){v, head[u]};
  head[u] = cnt;
}
void dfs(int u, int fa, int dis) {
  if (ans < dis) ans = dis, rt = u;
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u, dis + deg[v]);
  }
}
void solve() {
  scanf("%d", &n);
  cnt = rt = 0;
  for (int i = 1; i <= n; i++) deg[i] = -1, head[i] = 0;
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
    deg[x]++;
    deg[y]++;
  }
  ans = 0;
  dfs(1, 0, deg[1]);
  ans = 0;
  dfs(rt, 0, deg[rt]);
  printf("%d\n", ans + 2);
}
int main() {
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
