#include <bits/stdc++.h>
using namespace std;
const int N = 330000;
vector<int> adj[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int ncase;
  for (cin >> ncase; ncase--;) {
    int n;
    cin >> n;
    vector<int> dp(n + 1, 0);
    vector<int> ans(n + 1, 0);
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    function<void(int, int)> dfs = [&](int u, int p) {
      ans[u] = adj[u].size();
      dp[u] = adj[u].size();
      for (int v : adj[u]) {
        if (v == p) continue;
        dfs(v, u);
        ans[u] = max(ans[u], ans[v]);
        ans[u] = max(ans[u], dp[u] + dp[v] - 1);
        dp[u] = max(dp[u], dp[v] + (int)adj[u].size() - 1);
      }
    };
    dfs(1, 0);
    cout << ans[1] + 1 << "\n";
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
    }
  }
  return 0;
}
