func_code_string: //////////////////////////// ****   JAI SHREE RAM   **** //////////////////////////   #include<bits/stdc++.h>   #include<unordered_map>   using namespace std;   #define int long long int   #define double long double   void fun() {   #ifndef ONLINE_JUDGE   freopen( input.txt ,  r , stdin);freopen( output.txt ,  w , stdout);      #endif   }   int __gcd(int a, int b) {if(b==0) return a; return __gcd(b, a%b);}   int poww(int a, int b, int md) {if(b<0) return 0; if(a==0) return 0; int res=1;       while(b) {if(b&1){res=(1ll*res*a)%md;}a=(1ll*a*a)%md;b>>=1;}return res;}   int divide(int a, int b, int md) {int rr=a*(poww(b, md-2, md));rr%=md;return rr;}   //////////////////////////////////////////////////////////////////////////////////   //////////////////////////////////////////////////////////////////////////////////   const int siz = 2e5 + 5;   int ans;   //////////////////////////////////////////////////////////////////////////////////   int dfs(int node, int gpar, vector<int> g[]) {    int minchild = 1e9;    int maxchild = 0;    vector<int> nodedepth;    for(int child : g[node]) {     if(child != gpar) {      int returnpath = dfs(child, node, g) + 1;      minchild = min(minchild, returnpath);      maxchild = max(maxchild, returnpath);      if(node == 1) {       nodedepth.push_back(returnpath);      }     }    }    if(node == 1) {     sort(nodedepth.begin(), nodedepth.end());    }     if(minchild == 1e9) {     ans = max(ans, 0ll);     return 0;    }    if(node == 1) {     if(g[node].size() > 1) {      ans = max(ans, maxchild);      minchild = nodedepth[nodedepth.size() - 2];      ans = max(ans, minchild + 1);     } else {      ans = max(ans, maxchild);     }    } else {     if(g[node].size() > 2) {      ans = max(ans, minchild);      ans = max(ans, maxchild + 1);     } else {      ans = max(ans, minchild);     }    }    return minchild;   }   signed main() {       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); fun();       int t; cin >> t;       while(t--) {        int n, u, v; cin >> n;        vector<int> g[n + 1];        for(int i = 1; i < n; i++) {         cin >> u >> v;         g[u].push_back(v);         g[v].push_back(u);        }        ans = INT_MIN;        dfs(1, 0, g);        cout << ans <<   n ;       }       return 0;   }                                                                           