#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 7;
int head[maxn], top, deg[maxn];
struct edge {
  int v;
  int next;
} e[maxn << 1];
void add(int u, int v) {
  e[top].v = v;
  e[top].next = head[u];
  head[u] = top++;
}
int id, ans;
void dfs(int u, int father, int path) {
  if (path > ans) {
    ans = path;
    id = u;
  }
  int i;
  for (i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    int w = deg[v];
    if (v != father) dfs(v, u, path + w);
  }
}
int main() {
  int q;
  cin >> q;
  memset(head, -1, sizeof(head));
  while (q--) {
    int n, i;
    cin >> n;
    if (n > 1) {
      int u, v;
      top = 0;
      for (i = 1; i < n; i++) {
        cin >> u >> v;
        add(u, v);
        add(v, u);
        deg[u]++;
        deg[v]++;
      }
      for (i = 1; i <= n; i++) deg[i]--;
      ans = 0;
      dfs(1, 0, deg[1]);
      ans = 0;
      dfs(id, 0, deg[id]);
      ans += 2;
    } else
      ans = 1;
    cout << ans << endl;
    for (i = 0; i <= n; i++) {
      head[i] = -1;
      deg[i] = 0;
    }
  }
  return 0;
}
