#include <bits/stdc++.h>
using namespace std;
class trio {
 public:
  long long first, second, third;
};
long long ans;
list<long long>* adj;
long long dfs(long long i, long long pa) {
  vector<long long> v;
  for (auto it : adj[i]) {
    if (it != pa) {
      v.push_back(dfs(it, i));
    }
  }
  if (v.size() == 0) {
    ans = max(ans, (long long)1);
    return 1;
  }
  sort(v.begin(), v.end(), greater<long long>());
  if (v.size() == 1) {
    ans = max(ans, v[0] + 1);
    return v[0] + 1;
  }
  ans = max(ans, v[0] + v[1] + 1 + (long long)adj[i].size() - 2);
  return v[0] + (long long)adj[i].size() - 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long q;
  cin >> q;
  while (q--) {
    long long n, x, y;
    cin >> n;
    ans = 0;
    adj = new list<long long>[n + 1];
    for (long long i = 1; i < n; ++i) {
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(1, -1);
    cout << ans << endl;
  }
  return 0;
}
