// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(int i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl 1000000007

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

void test_case() {
	ll n, m, q;
	cin >> n;
	vector<pll> v[n + 1], query[n + 1];

	for (int i = 0; i < n - 1; i++) {
		ll x, y, w;
		cin >> x >> y >> w;
		v[x].push_back({y, w});
		v[y].push_back({x, w});
	}

	vector<ll> ans(n + 1, 0), sub(n + 1, 0), pre(n + 1, 0);

	function<void(ll, ll)> dfs = [&](ll s, ll p) {
		sub[s] = 0;

		for (auto zx : v[s]) {
			if (zx.ff != p) {
				dfs(zx.ff, s);
				// debug(s, zx.ss + sub[zx.ff]);
				if (zx.ss + sub[zx.ff] >= sub[s]) {
					pre[s] = sub[s];
					sub[s] = zx.ss + sub[zx.ff];
				} else if (zx.ss + sub[zx.ff] >= pre[s]) {
					pre[s] = zx.ss + sub[zx.ff];
				}
			}
		}
	};


	function<void(ll, ll, ll)> bfs = [&](ll s, ll p, ll up) {
		if (s != 1) {
			debug(s);

			for (auto zx : v[s]) {
				if (zx.ff != p) {
					sub[zx.ff] = max(sub[zx.ff], zx.ss + up);

					debug(zx.ff, s, zx.ss + up);
					bfs(zx.ff, s, zx.ss + up);
				}
			}
		} else {
			for (auto zx : v[s]) {
				if (zx.ff != p) {
					if (zx.ss + sub[zx.ff] == sub[s]) {
						sub[zx.ff] = max(sub[zx.ff], zx.ss + pre[s]);

						debug(zx.ff, s, zx.ss + pre[s]);
						bfs(zx.ff, s, zx.ss + pre[s]);
					} else {
						sub[zx.ff] = max(sub[zx.ff], zx.ss + sub[s]);

						debug(zx.ff, s, zx.ss + sub[s]);
						bfs(zx.ff, s, zx.ss + sub[s]);
					}
				}
			}
		}
		// 12 9 7 12
	};

	dfs(1, -1);
	bfs(1, -1, 0);

	for (int i = 1; i < n + 1; i++)
		cout << sub[i] << ' ';
	cout << "\n";

	debug(sub, pre);
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll tc;
	cin >> tc;
	while (tc--)
		test_case();
	return 0;
}
