Be like Radia!

0

0 votes
Problem

Radia Pearlmen

Radia Perlman is a software developer who invented the STP (Spanning-Tree Protocol), which is fundamental to the operation of the Internet. She made many notable contributions to network design and standardization including link-state protocols. She is also the inventor of  TRILL, a software that overcomes the shortcomings of spanning-trees. A pioneer in computer programming, she holds over 100 issued patents.She completed her higher education from Ocean Township High school.

The red house of Ocean Township High School had N students. A new student had to be appointed as the captain of the house. Before appointing the new captain, the students were needed to be organised as follows:

1) Every student(other than the captain) must have a leader assigned to him/her who is studying in class higher than that student. A captain cannot have a leader.

2) A student(including the captain) in class C can be a leader to maximum C students. (if a student X is a leader of Y and Y is a leader of Z then X is not a leader of Z) .

3) The captain will be someone new and not someone among the N students.

Radia being an exceptional student, was asked by the faculty to determine the minimum possible value of class from which a captain can be chosen?

Input:

The first line of the input gives the number of test cases, T

T test cases follow.

Each begins with one line with an integer P - the number of different classes present among the students. 

Then, P lines follow :

the ith of these contains two integers Ni and Ci, and indicates that there are Ni number of existing students in the house that are in the class Ci.

Output:

For each test case, print the minimum possible value of class from which a captain can be chosen, as described above.

Constraints:

1 ≤ T ≤ 100

1 ≤ P ≤ 1000

1 ≤ N ≤ 1012

1 ≤ Ci ≤ 100000

 

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?