#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int> (3));
    for(int i=0; i<n; i++) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }
    vector<int> num(2*n+2, 0);
    for(int i=0; i<n; i++) {
        num[v[i][0]]+=v[i][2];
        num[v[i][1]]+=v[i][2];
        //cout << v[i][0] <<" "<< v[i][1] <<" "<< v[i][2] <<" " << num[v[i][0]] << endl;
    }
    cout << *max_element(num.begin(), num.end()) << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
}
