#include <bits/stdc++.h>
using namespace std;
const int Maxn = 300000 + 20, inf = 0x3f3f3f3f;
int edgecnt, head[Maxn], to[Maxn << 1], nxt[Maxn << 1];
int d[Maxn], ans, s;
int n;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s * w;
}
inline void add(int x, int y) {
  ++edgecnt;
  nxt[edgecnt] = head[x];
  to[edgecnt] = y;
  head[x] = edgecnt;
  d[y]++;
}
void dfs(int x, int fa, int dis) {
  if (dis > ans) ans = dis, s = x;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) continue;
    dfs(y, x, dis + d[x]);
  }
}
int main() {
  int T = read();
  while (T--) {
    n = read();
    for (int i = 1; i <= n; ++i) d[i] = -1, head[i] = 0;
    ans = 0, s = 0;
    for (int i = 1; i < n; ++i) {
      int x = read(), y = read();
      add(x, y);
      add(y, x);
    }
    dfs(1, 0, d[1]);
    ans = 0;
    dfs(s, 0, d[s]);
    printf("%d\n", ans + 2);
  }
  return 0;
}
