#include <bits/stdc++.h>
using namespace std;
vector<int> edges[300300];
bool v[300300];
int ans;
int dfs(int x) {
  v[x] = true;
  int m1 = 1, m2 = 1;
  for (auto son : edges[x]) {
    if (!v[son]) {
      int m3 = dfs(son);
      if (m3 > m2) swap(m2, m3);
      if (m2 > m1) swap(m1, m2);
    }
  }
  int st = (int)edges[x].size() + m1 - (x != 1);
  ans = max(ans, st + m2 - 1 + (x != 1));
  v[x] = false;
  return st;
}
void doit() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    edges[i].clear();
  }
  ans = 0;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  dfs(1);
  printf("%d\n", ans);
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    doit();
  }
}
