import java.io.*;
import java.util.*;

class Most{
	
	public static void main(String[] args) throws IOException{
		Most instance = new Most();
		instance.run();
	}
	
	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	void run() throws IOException{
		String line;
		
		while((line = reader.readLine()) != null){
			int n = Integer.parseInt(line);
			
			for(int a = 0; a < n; a++){
				int bounds = Integer.parseInt(reader.readLine());
				int[][] b = new int[bounds][2];
				int min =  1000000;
			
				for(int i = 0; i < bounds; i++){
					String[] split = reader.readLine().split(" ");
					b[i][0] = Integer.parseInt(split[0]);
					b[i][1] = Integer.parseInt(split[1]);
				
					int dif = b[i][1] - b[i][0];
				
					if(dif< min)
						min = dif;
				}
			
				for(int i = 0; i < bounds; i++){
					for(int j = i; j < bounds; j++){
						int sum = b[j][1] - b[i][0];
						if(sum < 0)
							sum = 0;
						int res = sum + (j - i);
						if(res < min)
							min = res;
					}
				}
			
				System.out.println("K prechodu reky je treba " + min + " pontonu.");
			}
		}
		
	}
}