#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> G[N];
int f[N][2];
int n, x, y, res = 0;
void init() {
  res = 0;
  for (int i = 1; i <= n; i++) G[i].clear();
}
void dfs(int u, int p = 0) {
  f[u][0] = G[u].size(), f[u][1] = 0;
  for (auto v : G[u])
    if (v != p) {
      dfs(v, u);
      f[u][1] = max(f[u][1], f[u][0] + f[v][0] - 1);
      f[u][0] = max(f[u][0], f[v][0] + (int)G[u].size() - 1);
    }
  res = max(res, f[u][1]);
}
void work() {
  cin >> n;
  init();
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1);
  ++res;
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) work();
  return 0;
}
