#include <bits/stdc++.h>
using namespace std;
vector<int> v[300005];
int RES;
int solve(int u, int dad = 0) {
  if (dad && v[u].size() == 1) return 1;
  int mx = 0, smx = 0;
  for (auto i : v[u])
    if (i != dad) {
      int now = solve(i, u);
      if (now > mx)
        smx = mx, mx = now;
      else if (now > smx)
        smx = now;
    }
  RES = max(RES, mx + smx - 1 + (int)v[u].size());
  return mx + v[u].size() - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T, n;
  for (cin >> T; T--;) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      v[i].clear();
    }
    for (int i = n, x, y; --i;) {
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    int ROOT = 0;
    for (int i = 1; i <= n; ++i)
      if (v[i].size() > 1) ROOT = i;
    RES = 2;
    if (ROOT) solve(ROOT);
    cout << RES << endl;
  }
}
