// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 2e5 + 10;
vector <int> g[sz];
ll ans;

ll dfs(ll u, ll p)
{
    if(g[u].size() == 1 && u != 1)
        return 1;

    vector <int> cst;

    for(int &v : g[u]) {
        if(v == p)
            continue;

        ll ret = dfs(v, u);
        cst.pb(ret);
    }
    sort(all(cst));

    ans = max(ans, (ll)cst[0]);

    if(cst.size() > 1) {
        if(u != 1)
            ans = max(ans, cst.back()+1LL);
        else
            ans = max({ans, (ll)cst.back(), (ll)cst[cst.size()-2]+1});
    }

    return cst[0] + 1;
}

int main()
{
    ll t;
    cin >> t;

    while(t--) {
        ll n; sl(n);

        for1(i, n) g[i].clear();

        for(ll i = 1; i < n; i++) {
            ll u, v;
            sl(u), sl(v);

            g[u].pb(v);
            g[v].pb(u);
        }

        ans = 0;
        dfs(1, -1);

        pf("%lld\n", ans);
    }

    return 0;
}

			 	 	      			 			    	 	 	