Omer has given you $$$n$$$ intervals by its endpoints $$$[l_{i}$$$, $$$r_{i}]$$$ and two groups, $$$A$$$ and $$$B$$$, initially empty.
For each interval, you can do at most one of the following operations:
1 Insert the interval into group $$$A$$$.
2 Insert the interval into group $$$B$$$.
At the end, every pair of intervals of the same group must intersect in at least one point. There aren't any restrictions for pairs of intervals of different groups.
Your task is to maximize the size of the smallest group.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 1000)$$$. The description of the test cases follows.
The first line consists in one integer $$$n$$$ $$$(2 \leq n \leq 3 \cdot 10^{5})$$$ — the number of intervals.
Then follows $$$n$$$ lines which consists in two integers $$$l_{i}$$$ and $$$r_{i}$$$ $$$(1 \leq l_{i} \leq r_{i} \leq 10^{9})$$$ — the endpoints of the intervals.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^{5}$$$.
—
Testcases in subtasks are numbered from $$$1$$$ to $$$20$$$ with samples skipped.
Tests $$$1-3$$$: $$$(2 \leq n \leq 500)$$$ and it is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$500$$$.
Tests $$$4-7$$$: $$$(2 \leq n \leq 3000)$$$ and it is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
Tests $$$8-12$$$: $$$(2 \leq n \leq 10^{5})$$$ and it is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^{5}$$$.
Tests $$$13-20$$$: No additional constraints.
Each test is worth $$$5$$$ points with samples skipped.
For each testcase, output one integer per line, the maximum possible size of the smallest group.
2 5 4 7 1 8 7 12 2 6 13 13 2 69 69 69 69
2 1
For the first testcase, a possible distribution would be $$$A$$$ = $$$([2, 6], [4, 7])$$$ and $$$B$$$ = $$$([1, 8], [7, 12])$$$.
For the second testcase, the unique possible distribution is $$$A$$$ = $$$([69, 69])$$$ and $$$B$$$ = $$$([69, 69])$$$.
—
Problem Idea: danx
Problem Preparation: danx
Occurrences: Advanced 10