#include <bits/stdc++.h>
#include <iomanip>
#include<iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define all(a)  a.begin(),a.end()
#define death ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) ((int)(x).size())
#define el "\n"
#define basmala freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define int ll
/****************************************************************************/
int dx[] = {0,  0, 1, -1};
int dy[] = {1, -1, 0,  0};
int di[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dj[] = {1, 0, -1, 1, -1, 1, 0, -1};
ll mod=998244353;
const int N=1e5+4;
vector<pair<int,int>>adj[N];
int dist1[N],dist2[N];
/****************************************************************************/
void bfs(int node, int d[]){
    queue<int>q;
    q.push(node);
    fill(d, d + N, -1);
    d[node]=0;
    while(sz(q)){
        int curr=q.front();
        q.pop();
        for(auto [v,w]:adj[curr]){
            if(d[v]==-1){
                d[v]=d[curr]+w;
                q.push(v);
            }
        }
    }
}
/****************************************************************************/
void neverland(){
    int n; cin>>n;
    for(int i=0;i<n;i++)
        adj[i].clear();
    int m=n-1;
    while(m--){
        int a,b,c; cin>>a>>b>>c;
        adj[a].emplace_back(b,c);
        adj[b].emplace_back(a,c);
    }
    bfs(1,dist1);
    int far = max_element(dist1+1,dist1+n+1)-dist1;
    bfs(far,dist1);
    int far2 = max_element(dist1+1,dist1+n+1)-dist1;
    bfs(far2,dist2);
    for(int i=1;i<=n;i++)
        cout<<max(dist1[i],dist2[i])<<" ";
    cout<<el;
}
signed main() {
    // basmala;
    death;
    int t=1; cin>>t;
    while(t--) neverland();
}