Problem: There are departments in the mall, each of which has exactly two stores. For convenience, we number the departments with integers from to . It is known that gifts in the first store of the department cost rubles, and in the second store of the department — rubles.
Entering the mall, Sasha will visit each of the departments of the mall, and in each department, he will enter exactly one store. When Sasha gets into the -th department, he will perform exactly one of two actions:
- Buy a gift for the first friend, spending rubles on it.
- Buy a gift for the second friend, spending rubles on it.
Sasha is going to buy at least one gift for each friend. Moreover, he wants to pick up gifts in such a way that the price difference of the most expensive gifts bought for friends is as small as possible so that no one is offended.
More formally: let be the maximum price of a gift bought to the first friend, and be the maximum price of a gift bought to the second friend. Sasha wants to choose gifts in such a way as to minimize the value of .
Input Format: Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the number of departments in the mall.
Each of the following lines of each test case contains two integers and () — the prices of gifts in the first and second store of the department, respectively.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format: Print one integer — the minimum price difference of the most expensive gifts bought to friends.
Note: In the first test case, Sasha has two possible options: buy a gift for the first friend in the first department, and the second friend — in the second department, or vice versa. In the first case, , and in the second case — . In both cases, the answer is . In the second test case, you can buy gifts for the first friend in the , and departments, and for the second friend — in the and departments.So , . The answer is .