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

void solve() {
    int n;
    cin>>n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n;i++) {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll res = 0;
    for (int i = 1; i <= 2 * n; i++) {
        ll cr = 0;
        for (int j = 0; j < n; j++) {
            if (a[j] == i || b[j] == i) {
                cr += c[j];
            }
        }
        res = max(res, cr);
    }
    cout << res << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin>>t;
    while (t) {
        solve();
        t--;
    }
}
