#include <bits/stdc++.h>

using namespace std;

#define print(a) cerr << "[" << #a << " = " << a << "] "
#define dbg(a) print(a) << "\n"
#define dbg2(a, b) print(a); print(b) << "\n"

#define int long long
#define ll long long
#define pi pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define divup(a, b) (((a) + (b) - 1) / (b))

template <class T> bool chmax(T&a, const T&b) {return b > a ? a = b, 1 : 0;};
template <class T> bool chmin(T&a, const T&b) {return b < a ? a = b, 1 : 0;};

const int mod = 1e9 + 7;
const int inf = (int)(1e18) + 7;

const int maxn = 2e5 + 7;
const int N = 1e4 + 7;
const int logn = 20;

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];
    }

    int ans = 0;
    for (int i = 1; i <= 2 * n; ++i) {
        int cur = 0;
        for (int t = 0; t < n; ++t) {
            // dbg2(a[t], b[t]);
            if (a[t] == i || b[t] == i) cur += c[t];
        }
        ans = max(ans, cur);
    }
    for (int i = 1; i <= 2 * n; ++i) {
        for (int j = i + 1; j <= 2 * n; ++j) {
            for (int k = j + 1; k <= 2 * n; ++k) {
                int cur = 0;
                set <int> s;
                s.insert(i);
                s.insert(j);
                s.insert(k);
                for (int t = 0; t < n; ++t) {
                    if (s.count(a[t]) && s.count(b[t])) cur += c[t];
                }
                chmax(ans, cur);
            }
        }
    }

    cout << ans << '\n';
}

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

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        cerr << "###########";
    }
} 