#d2957. nice party

nice party

Nice Party

Problem Description

cc is going to throw a party and invites his friends so that everyone has a good time.

cc has nn friends; the ii-th friend has net worth ii.

The ii-th friend will attend the party and enjoy it if and only if there are at most XiX_i people present whose net worth is strictly greater than his, and at most YiY_i people whose net worth is strictly smaller than his.

cc wants to know: what is the maximum number of friends he can invite such that every invited friend enjoys the party?

Input Format

The first line gives an integer TT, the number of test cases (1≤T≤1041 \le T \le 10^4).

For each test case:

  • The first line gives an integer nn (1≤∑n≤2×1051 \le \sum n \le 2 \times 10^5), the number of friends.
  • The following nn lines each give two integers XiX_i and YiY_i (0≤Xi,Yi<n0 \le X_i, Y_i < n).

Output Format

For each test case, output one integer: the maximum number of friends cc can invite.

Sample Input

3
3
1 2
2 1
1 1
2
0 0
0 1
2
1 0
0 1

Sample Output

2
1
2