#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > adj[50000+5];
pair<int,int> dijkstra(int x,int n){
bool vis[n+1];
int dist[n+1];
for(int i=0;i<=n;i++){
dist[i]=1000000;
vis[i]=false;
}
dist[x]=0;
multiset<pair<int,int> >s;
s.insert({0,x});
while(!s.empty()){
pair<int,int> p=*s.begin();
s.erase(s.begin());
int x=p.second;
int wei=p.first;
if(vis[x])
continue;
vis[x]=true;
for(int i=0;i<adj[x].size();i++){
int e=adj[x][i].first;
int w=adj[x][i].second;
if(dist[x]+w<dist[e]){
dist[e]=dist[x]+w;
s.insert({dist[e],e});
}
}
}
int node,weight=0;
for(int i=1;i<=n;i++){
if(dist[i]>weight){
node=i;
weight=dist[i];
}
}
return make_pair(node,weight);
}
int longestPath(int n){
pair<int,int> t1,t2;
t1=dijkstra(1,n);
t2=dijkstra(t1.first,n);
return t2.second;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<=n;i++)
adj[i].clear();
int a,b,l;
for(int i=0;i<n-1;i++){
cin>>a>>b>>l;
adj[a].push_back({b,l});
adj[b].push_back({a,l});
}
cout<<longestPath(n)<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdmVjdG9yPHBhaXI8aW50LGludD4gPiBhZGpbNTAwMDArNV07CnBhaXI8aW50LGludD4gZGlqa3N0cmEoaW50IHgsaW50IG4pewogICAgYm9vbCB2aXNbbisxXTsKICAgIGludCBkaXN0W24rMV07CiAgICBmb3IoaW50IGk9MDtpPD1uO2krKyl7CiAgICAgICAgZGlzdFtpXT0xMDAwMDAwOwogICAgICAgIHZpc1tpXT1mYWxzZTsKICAgIH0KICAgIGRpc3RbeF09MDsKICAgIG11bHRpc2V0PHBhaXI8aW50LGludD4gPnM7CiAgICBzLmluc2VydCh7MCx4fSk7CiAgICB3aGlsZSghcy5lbXB0eSgpKXsKICAgICAgICBwYWlyPGludCxpbnQ+IHA9KnMuYmVnaW4oKTsKICAgICAgICBzLmVyYXNlKHMuYmVnaW4oKSk7CiAgICAgICAgaW50IHg9cC5zZWNvbmQ7CiAgICAgICAgaW50IHdlaT1wLmZpcnN0OwogICAgICAgIGlmKHZpc1t4XSkKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgdmlzW3hdPXRydWU7CiAgICAgICAgZm9yKGludCBpPTA7aTxhZGpbeF0uc2l6ZSgpO2krKyl7CiAgICAgICAgICAgIGludCBlPWFkalt4XVtpXS5maXJzdDsKICAgICAgICAgICAgaW50IHc9YWRqW3hdW2ldLnNlY29uZDsKICAgICAgICAgICAgaWYoZGlzdFt4XSt3PGRpc3RbZV0pewogICAgICAgICAgICAgICAgZGlzdFtlXT1kaXN0W3hdK3c7CiAgICAgICAgICAgICAgICBzLmluc2VydCh7ZGlzdFtlXSxlfSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBpbnQgbm9kZSx3ZWlnaHQ9MDsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKXsKICAgICAgICBpZihkaXN0W2ldPndlaWdodCl7CiAgICAgICAgICAgIG5vZGU9aTsKICAgICAgICAgICAgd2VpZ2h0PWRpc3RbaV07CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIG1ha2VfcGFpcihub2RlLHdlaWdodCk7Cn0KCmludCBsb25nZXN0UGF0aChpbnQgbil7CiAgICBwYWlyPGludCxpbnQ+IHQxLHQyOwogICAgdDE9ZGlqa3N0cmEoMSxuKTsKICAgIHQyPWRpamtzdHJhKHQxLmZpcnN0LG4pOwogICAgcmV0dXJuIHQyLnNlY29uZDsKfQoKaW50IG1haW4oKXsKICAgIGludCB0OwogICAgY2luPj50OwogICAgd2hpbGUodC0tKXsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4+Pm47CiAgICAgICAgZm9yKGludCBpPTA7aTw9bjtpKyspCiAgICAgICAgICAgIGFkaltpXS5jbGVhcigpOwogICAgICAgIGludCBhLGIsbDsKICAgICAgICBmb3IoaW50IGk9MDtpPG4tMTtpKyspewogICAgICAgICAgICBjaW4+PmE+PmI+Pmw7CiAgICAgICAgICAgIGFkalthXS5wdXNoX2JhY2soe2IsbH0pOwogICAgICAgICAgICBhZGpbYl0ucHVzaF9iYWNrKHthLGx9KTsKICAgICAgICB9CiAgICAgICAgY291dDw8bG9uZ2VzdFBhdGgobik8PGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==