#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=2e5+5;
const int inf=1e9;
vector<int> adj[mxn];
int sm[mxn];
int level[mxn];
bool can = true;


int dfs(int cur,int prev,int k) {
	int c = 0;
	int mgx = 0;
	int mn = inf;
	int mx = 0;
	for(int u : adj[cur]) {
		if(u == prev) continue;
		c++;
	}

	for(int u : adj[cur]) {
		if(u == prev) continue;
		int v = dfs(u,cur,k);
		if(v >= k) {
			mgx++;
		}
		mn = min(mn,v);
		mx = max(mx,v);
	}

	if(mx > k) {
		can = false;
		return inf;
	}


	if(mgx >= 2) {
		can = false;
		return inf;
	}
	if(mgx == 1) {
		if(cur != 1) {
			can = false;
			return inf;
		}
	}

	if(c == 0) {
		return 1;
	}

	return mn + 1;

}

void solve() {
	int n;
	cin>>n;
	for(int i = 1; i <= n; i++) adj[i].clear();

	for(int i = 1; i < n; i++) {
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}	

	int k = n;
	int lo = 1;
	int hi = n;
	while(lo <= hi) {
		int mid = lo + hi >> 1;
		can = true;
		dfs(1,0,mid);
		if(can) {
			hi = mid - 1;
			k = mid;
		} else {
			lo = mid + 1;
		}

	}

	cout<<k<<endl;


}
int main() {

	int t=1;
	cin>>t;
	while(t--)solve();
	
}