#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define str string
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int) a.size()
#define fi first
#define se second
using namespace __gnu_pbds;
#define o_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;

mt19937 rng(474);

int getnum(int l,int r){
    uniform_int_distribution<int> dist(l,r);
    return dist(rng);
}

void solve(){
    int n;
    cin >> n;
    vector<int> ans(2*n+1,0);
    vector<int> a(n), b(n), c(n);
    for(int i = 0;i<n;++i){
        cin >> a[i] >> b[i] >> c[i];
        ans[a[i]] += c[i];
        ans[b[i]] += c[i];
    }
    int res = 0;
    for(int i = 1;i<=2*n;++i) res = max(res,ans[i]);
    cout << res << '\n';
}

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

    int tt;
    cin >> tt;
    while(tt--) solve();
}