import java.io.FileReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
	static node[] data;
	static int[][][] opt_map;
	static int[][] opt;
	static int time, num_items;
	
	static {
		data = new node[100];	
		opt_map = new int[101][241][3];
		opt = new int[101][241];
	}
	
	static class node{
		int time, score;
		String name;
		node(int t, int s, String n) {
			score = s; name = n; time = t;
		}
		void print(StringBuilder out) {
			out.append(String.format("%3d%7d   %s\n", score, time, name));
		}
	}
	
	static class comp implements Comparator<node> {
		public int compare(node a, node b) {
			if (a.time == b.time && a.score == b.score) return a.name.compareTo(b.name);
			if (a.time == b.time) return b.score - a.score;
			return a.time - b.time;
		}
	}
	
	static void calculate() {	
		for (int i = 0; i <= num_items; i++) {
			for (int j = 0; j <= time; j++) {
				opt_map[i][j][0] = opt_map[i][j][1] = opt_map[i][j][2] = 0;
				opt[i][j] = 0;
			}
			opt_map[i][0][2] = -2;
		}
		
		for (int j = 0; j <= time; j++) {
			opt_map[0][j][2] = -2;
		}
		
		for (int i = 1; i <= num_items; i++) {
			node n = data[i - 1];
			for (int t = 0; t < n.time && t <= time; t++) {
				opt_map[i][t][0] = i - 1;
				opt_map[i][t][1] = t;
				opt_map[i][t][2] = 0;
				opt[i][t] = opt[i - 1][t];
			}
			for (int t = n.time; t <= time; t++) {
				if (opt[i - 1][t] > n.score + opt[i - 1][t - n.time]) {
					opt_map[i][t][0] = i - 1;
					opt_map[i][t][1] = t;
					opt_map[i][t][2] = 0;
					opt[i][t] = opt[i - 1][t];
				} else {
					opt_map[i][t][0] = i - 1;
					opt_map[i][t][1] = t - n.time;
					opt_map[i][t][2] = 1;
					opt[i][t] = opt[i - 1][t - n.time] + n.score;
				}
			}
		}
	}
	
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
		int num_cases = in.nextInt();
		StringBuilder out = new StringBuilder();
		for (int i = 0; i < num_cases; i++) {
			if (i !=  0) out.append("\n");
			num_items = 0;
			time = in.nextInt();
			in.nextLine();
			while (in.hasNext()) {
				String[] input = in.nextLine().split(" ", 3);
				if (input.length < 2) break;
				int v = Integer.parseInt(input[0]), t = Integer.parseInt(input[1]);
				node n = new node(t, v, input[2]);
				data[num_items] = n;
				num_items++;				
			}
			
			Arrays.sort(data, 0, num_items, new comp());
			
			calculate();
		
			int opt_time = opt[num_items][time];
			
			if (opt_time == 0) {
				out.append("There is not enough time to present any evidence. Drop the charges.\n");
			} else {
				out.append("Score  Time  Description\n");
				out.append("-----  ----  -----------\n");
				
				node[] list = new node[num_items];
				int list_length = 0;
				int n = num_items, t = time;
				while (opt_map[n][t][2] != -2) {
					if (opt_map[n][t][2] == 1)
						list[list_length++] = data[n - 1];
					int next = opt_map[n][t][0];
					t = opt_map[n][t][1];
					n = next;
				}
				
				t = 0;
				for (int k = list_length; --k >= 0;) {
					t += list[k].time;
					list[k].print(out);			
				}
				
				out.append("\nTotal score: " + opt[num_items][time] + " points\n");
				out.append(" Total time: " + t + " hours\n");
			}
		}
		
		System.out.print(out);
	}	
}
