import java.util.ArrayList; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author kontris */ public class most { static Scanner sc = new Scanner(System.in); public static void main(String args[]) { int count = sc.nextInt(); for (int q = 0; q < count; q++) { int k = sc.nextInt(); int rozmery[][] = new int[k][3]; int min = Integer.MAX_VALUE; for (int i = 0; i < k; i++) { rozmery[i][0] = sc.nextInt(); rozmery[i][2] = sc.nextInt(); rozmery[i][1] = rozmery[i][2] - rozmery[i][0]; if (rozmery[i][1] < min) min = rozmery[i][1]; } ArrayList pole = new ArrayList<>(); for (int i = 0; i < k; i++) { if (rozmery[i][1] == min) pole.add(i); } for (int i = 0; i < pole.size() - 1; i++) { for (int j = i + 1; j < pole.size(); j++) { int x = rozmery[pole.get(j)][2] - rozmery[pole.get(i)][0] + pole.get(j) - pole.get(i); if (x < min) min = x; } } System.out.println("K prechodu reky je treba " + min + " pontonu."); } } }