CF BUDDY
← Problems·

1488C · Two Policemen

1900 · *special, binary search, brute force

Problem: There is a street that can be represented as an array of length nn.

There are two policemen patrolling a street: the first one is standing at the point xx of the street and the second one is standing at the point yy of the street.

During one minute, both policemen can decide what to do (independently): move left (if the current position is greater than 11), move right (if the current position is less than nn), or do nothing.

The street is considered clear if each point of the street is visited by at least one policeman.

Your task is to find the minimum number of minutes the policemen need to visit each point of the street (again, each point should be visited by at least one of them).

You have to answer tt independent test cases.

Input Format: The first line of the input contains one integer tt (1t21041 \le t \le 2 \cdot 10^4) — the number of test cases. Then tt test cases follow.

The only line of the test case contains three integers nn, xx and yy (2n1062 \le n \le 10^6; 1x,yn1 \le x, y \le n; xyx \ne y) — the length of the street, the position of the first policeman and the position of the second policeman, respectively.

It is guaranteed that the sum of nn does not exceed 10610^6 (n106\sum n \le 10^6).

Output Format: For each test case, print one integer — the minimum number of minutes the policemen need to visit each point of the street.

Sample Cases

Case 1

Input

6
4 1 2
7 7 1
10 2 6
8 5 2
2 1 2
20 4 14

Output

2
3
5
4
0
12

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback