// Arup Guha
// 4/28/2015
// Solution to 2015 FHSPS Problem: Radio

import java.util.*;

public class radio implements Comparable<radio> {

    public int day;
    public int value;
    public int wait;

    public radio(int myDay, int myValue, int myWait) {
        day = myDay;
        value = myValue;
        wait = myWait;
    }

	// So we can sort prizes by day easily.
    public int compareTo(radio other) {
        return this.day - other.day;
    }

    public static void main(String[] args) {

    	Scanner stdin = new Scanner(System.in);
    	int numCases = stdin.nextInt();

		// Go through each case.
    	for (int loop=1; loop<=numCases; loop++) {

			// Read in the prizes
    		int n = stdin.nextInt();
    		radio[] list = new radio[n];
    		for (int i=0; i<n; i++) {
    			int day = stdin.nextInt();
    			int value = stdin.nextInt();
    			int wait = stdin.nextInt();
    			list[i] = new radio(day, value, wait);
    		}
    		Arrays.sort(list);

    		// Solve and output.
    		System.out.println(getMaxCash(list));
    	}
    }

	// Solves a single instance of the given problem.
    public static int getMaxCash(radio[] prizes) {

		// If there is only one prize, we can grab it.
    	int[] dp = new int[prizes.length];
    	dp[0] = prizes[0].value;
    	int res = dp[0];

    	// Fill in each item, in order.
    	for (int i=1; i<dp.length; i++) {

    		// You can always just have this prize.
    		dp[i] = prizes[i].value;

    		// Try building off each previous prize to see which is the best.
    		for (int j=0; j<i; j++) {

    			// Can't build off prize j, since you'd have to wait too long to get i also.
    			if (prizes[j].wait+prizes[j].day > prizes[i].day) continue;

    			// Take the better of the old way and building off j as your last prize before i.
    			dp[i] = Math.max(dp[i], dp[j]+prizes[i].value);
    		}

    		// Update our best total here.
    		res = Math.max(res, dp[i]);
    	}

		// Here is our answer.
    	return res;
    }
}
