#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300010;
int q, n, x, y, ans = 1;
vector<vector<int>> e(MAXN);
int dfs(int node, int parent) {
  if (e[node].size() == 1) return 1;
  int lg = 1, lg2 = 1;
  for (int ch : e[node]) {
    if (ch == parent) continue;
    int u = dfs(ch, node);
    if (u > lg) {
      lg2 = lg;
      lg = u;
    } else if (u > lg2)
      lg2 = u;
  }
  int cand = 1 + lg + lg2 + e[node].size() - 2;
  if (cand > ans) ans = cand;
  return (1 + lg + e[node].size() - 2);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    cin >> n;
    ans = 0;
    for (int i = 1; i <= n; ++i) e[i].clear();
    for (int i = 1; i < n; ++i) {
      cin >> x >> y;
      e[x].push_back(y);
      e[y].push_back(x);
    }
    if (n == 2) {
      cout << 2 << endl;
      continue;
    }
    int root = 1;
    while (e[root].size() == 1) root++;
    dfs(root, 0);
    cout << ans << endl;
  }
  return 0;
}
