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

struct S{
    long long a, b, c;
};

long long n, ans;
vector<S> arr;
vector<long long> v1;

long long check1(){
    v1.clear();
    v1.resize(2*n+5);
    for (int i = 0; i < n; i++){
        v1[arr[i].a] += arr[i].c;
        v1[arr[i].b] += arr[i].c;
    }
    long long res = 0;
    for (int i = 1; i <= 2*n; i++)
        res =  max(res, v1[i]);
    return res;
}

/*bool check(int i, int j, int k){
    return (A[i] == A[j] || B[i] == A[j] || A[i] == B[j] || B[i] == B[j]);
}*/


bool cmp(S s1, S s2){
    if (s1.a != s2.a)
        return (s1.a < s2.a);
    return (s1.b < s2.b);
}
long long check2(){
    long long res = 0;
    sort(arr.begin(), arr.end(), cmp);

    for (int i = 0; i < n-2; i++){
        int p1 = i+1, p2 = i+2;
        while (arr[p2].a < arr[i].b) p2++;
        while (1){
            if (p1 == p2) p2++;
            if (p2 >= n) break;
            if (arr[p1].a > arr[i].a) break;
            if (arr[p2].a > arr[i].b) break;
            if (arr[p1].b > arr[p2].b){
                p2++;
                continue;
            }
            if (arr[p1].b < arr[p2].b){
                p1++;
                continue;
            }
            res = max(res, arr[i].c+arr[p1].c+arr[p2].c);
            p1++;
        }
    }
    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    long long T = 1;
    cin >> T;
    for (int i = 0; i < T; i++){
        ans = 0;
        arr.clear();


        cin >> n;
        arr.resize(n);

        for (int j = 0; j < n; j++)
            cin >> arr[j].a >> arr[j].b >> arr[j].c;
        ans = max(check1(), check2());
        cout << ans << endl;
    }
    return 0;
}




