/* Compile with: g++ --std=c++17 main.cc -o M -W -fsanitize=address */

// 1. A subtree is left only if it is completed.
// 2. You only ever go up the tree from leaves.
// 3. If a node only has paths down to leaves (no other branching nodes),
//    it's weakly dominating to always save the highest leaf for last.
//    (rooted at non-root)
// 4. Induct up - we already know it's weakly dominating to save
//    highest leaf for last for subtree (rooted at non-root) of
//    order X. Then true for subtree (rooted at non-root) of order X+1 by
//    similar argument.
// 5. Special case for the end. Visit subtree with highest leaf LAST.

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
using ll = long long;

// parent[1] defined as -1
// Calculates Hld at node
void CalculateHld(int node, int par, const vector<vector<int>> &adj,
                  vector<int> *hld) {
  if (adj[node].size() == 1 && node != 1) {
    (*hld)[node] = 0;
    return;
  }

  int hld_min = INT_MAX;
  for (int c : adj[node]) {
    if (c == par)
      continue;
    CalculateHld(c, node, adj, hld);
    hld_min = min(hld_min, (*hld)[c] + 1);
  }
  (*hld)[node] = hld_min;
}

// v is the distance you'd have to jump if "node" were a leaf.
void ConsiderSubtree(int node, int par, int v, const vector<vector<int>> &adj,
                     const vector<int> &hld, int *ans) {
  if (adj[node].size() == 1) {
    *ans = max(*ans, v);
    return;
  }

  int min_hld = INT_MAX, min_hld_idx = -1;
  for (int c : adj[node]) {
    if (c == par)
      continue;
    if (hld[c] < min_hld) {
      min_hld = hld[c];
      min_hld_idx = c;
    }
  }

  for (int c : adj[node]) {
    if (c == par)
      continue;
    if (c == min_hld_idx) {
      ConsiderSubtree(c, node, v + 1, adj, hld, ans);
    } else {
      ConsiderSubtree(c, node, 2, adj, hld, ans);
    }
  }
}

void Solve() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> adj;
  adj.resize(n + 1);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vector<int> hld(n + 1, 0); // highest leaf distance
  CalculateHld(1, -1, adj, &hld);

  int max_hld = -1;
  int last_child = 0;
  for (int c : adj[1]) {
    if (hld[c] > max_hld) {
      max_hld = hld[c];
      last_child = c;
    }
  }

  int ans = 1;
  for (int c : adj[1]) {
    if (c == last_child)
      continue;
    ConsiderSubtree(c, 1, 2, adj, hld, &ans);
  }
  ConsiderSubtree(last_child, 1, 1, adj, hld, &ans);

  printf("%d\n", ans);
}

int main() {
  int t;
  scanf("%d", &t);
  while (t--)
    Solve();
}
