/* Class: COP3530
 * Date: March 31, 2006
 * Instructor: Arup Guha
 * TA: Adam Campbell
 *
 * Homework #4
 **/

import java.io.*;
import java.util.*;

public class Hw4{

	/* I have main throw exception so I don't need the try/catch blocks everywhere when reading in from the file.
	 * In general, this is not good programming practice, but for these simple problems we are more interested in the
	 *   algorithm.
	 **/
	public static void main(String[] args) throws Exception{

		BufferedReader fileReader = new BufferedReader(new FileReader("schedule.in"));
		StringTokenizer tokenizer;
		int n, k, start, end, max, maxIndex;
		boolean invalid;
		Event[] events;
		int[] times = new int[1020-480 + 1]; // keeps track of how much time has been scheduled up to the current time
		int[] eventUsed = new int[1020-480 + 1]; // allows us to print out the set of events that are in the solution

		// read in the number of test cases
		n = Integer.parseInt(fileReader.readLine());

		// loop through all test cases
		for(int testCase = 1; testCase <= n; testCase++){

			// number of events
			k = Integer.parseInt(fileReader.readLine());

			// read in events
			events = new Event[k];
			for(int i = 0; i < k; i++){

				tokenizer = new StringTokenizer(fileReader.readLine());

				start = Integer.parseInt(tokenizer.nextToken());
				end = Integer.parseInt(tokenizer.nextToken());

				// check to see if the event is invalid
				invalid = (start < 480 || end > 1020);

				// shift the start end end times over by 480
				events[i] = new Event(i+1, start-480, end-480, invalid);
							
			}

			// sort the events by ending time
			Arrays.sort(events);

			Arrays.fill(times, 0);
			Arrays.fill(eventUsed, -1);

			for(int i = 0; i < k; i++){

				// skip the event if it's invalid
				if(events[i].invalid) continue;

				max = 0;

				// find the most amount of time used before the current event
				for(int j = events[i].start; j >= 0; j--){
					if(times[j] > max){
						max = times[j];
					}
				}

				// now that we have found the max time BEFORE the starting time of the current
				//   event, we can add the new event if it's time plus the max time of the events
				//   before it is greater than the current max time found
				if(times[events[i].end] < max + (events[i].end - events[i].start)){

					times[events[i].end] = max + (events[i].end - events[i].start);
					eventUsed[events[i].end] = i;

				}
			}

			max = 0;

			// find the max time in the list
			for(int i = 0; i < times.length; i++){
				if(times[i] > max){
					max = times[i];
				}
			}

			System.out.println("Test case " + testCase + ":");
			System.out.println(max);
			
			printEvents(events, times, eventUsed, times.length-1);

			System.out.println();

		}

	}

	// this recursive function simply prints out the events in the order they were scheduled
	private static void printEvents(Event[] events, int[] times, int[] eventUsed, int curTime){

		int max, eventIndex;

		max = eventIndex = -1;

		for(int i = curTime; i >= 0; i--){
			if(times[i] > max){
				max = times[i];
				eventIndex = eventUsed[i];
			}
		}

		if(eventIndex > -1){
			printEvents(events, times, eventUsed, events[eventIndex].start);
			System.out.println(events[eventIndex].id);
		}

	}

	static class Event implements Comparable{

		int id, start, end;
		boolean invalid;

		public Event(int _id, int _start, int _end, boolean _invalid){
			this.id = _id;
			this.start = _start;
			this.end = _end;
			this.invalid = _invalid;
		}

		public int compareTo(Object obj){

			Event that = (Event)obj;

			if(this.end < that.end) return -1;
			if(this.end > that.end) return 1;

			return 0;

		}

	}

}
