
import java.util.Scanner;

/**
 *
 * @author cteam045
 */
public class Most {

    private static int solve(int[] shore1, int[] shore2){
        int vyska = shore1.length;
        int maxpos = 0;
        int mostp = 0;
        int minMost = Integer.MAX_VALUE;
        for (int i = 0; i < vyska; i++){
            if (maxpos <= shore1[i]) {
                maxpos = shore1[i];
                mostp = 0;                
            } else {
                mostp = Math.min(mostp+1, maxpos-shore1[i]);
            }
            minMost = Math.min(shore2[i]- maxpos + mostp, minMost);
        }
        maxpos = 0;
        mostp = 0;
        for (int i = vyska-1; i >= 0; i--){
            if (maxpos <= shore1[i]) {
                maxpos = shore1[i];
                mostp = 0;                
            } else {
                mostp = Math.min(mostp+1, maxpos-shore1[i]);
            }
            minMost = Math.min(shore2[i]- maxpos + mostp, minMost);
        }
        return minMost;
        }    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int pocetPripadu = sc.nextInt();
        for (int i = 0; i < pocetPripadu; i++){
            int vyska = sc.nextInt();
            int[] shore1 = new int[vyska];
            int[] shore2 = new int[vyska];
            for (int j = 0; j < vyska; j++){
                shore1[j] = sc.nextInt();
                shore2[j] = sc.nextInt();
            }
            System.out.printf("K prechodu reky je treba %d pontonu.\n", solve(shore1, shore2));
        }
    }
}
