#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
using pii = pair<int, int>;

signed main(){
    ios_base::sync_with_stdio();
    cin.tie();
    cout.tie();

    int t, n, a, b, c;
    cin >> t;

    while(t--) {
        cin >> n;

        vector<int> v(n * 2, 0);

        for(int i = 0; i < n; i++) {
            cin >> a >> b >> c;
            a--;
            b--;
            v[a] += c;
            v[b] += c;
        }

        for(int i: v) {
            cout << i << " ";
        }
        cout << "\n";

        cout << *max_element(all(v)) << "\n";
    }

    return 0;
}
// :)
