#include <bits/stdc++.h>
using namespace std;
int t, n, cnt, st, ed, ans, head[300005], val[300005];
struct edge {
  int to, nxt;
} e[600005];
void add(int u, int v) {
  e[++cnt].nxt = head[u];
  head[u] = cnt;
  e[cnt].to = v;
  val[u]++;
}
void dfs(int x, int fa, int dis) {
  int i, y;
  if (dis > ans) {
    ans = dis;
    st = x;
  }
  for (i = head[x]; i; i = e[i].nxt) {
    y = e[i].to;
    if (y == fa) continue;
    dfs(y, x, dis + val[y]);
  }
}
int main() {
  int i, u, v, t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 1; i <= n; i++) {
      head[i] = 0;
      val[i] = -1;
    }
    cnt = 0;
    for (i = 1; i < n; i++) {
      cin >> u >> v;
      add(u, v);
      add(v, u);
    }
    ans = -1;
    dfs(1, 0, val[1]);
    ans = -1;
    dfs(st, 0, val[st]);
    cout << ans + 2 << endl;
  }
  return 0;
}
