| The 2026 ICPC Belarus Qualification |
|---|
| Finished |
Svetozar does not go outside without a reason, of course. He has very important business in another district of the city. But how can he get there? Luckily, the city where Svetozar lives has a metro – and not an ordinary one, but one with a circular line!
The circular line consists of $$$n$$$ stations, numbered consecutively from $$$1$$$ to $$$n$$$ clockwise. Between any two neighboring stations there is a bidirectional segment: between stations $$$1$$$ and $$$2$$$, between $$$2$$$ and $$$3$$$, $$$\ldots$$$, between $$$n - 1$$$ and $$$n$$$, and also between $$$n$$$ and $$$1$$$. Trains can travel in both directions.
The fare for traveling along one segment between stations $$$u$$$ and $$$v$$$ depends on their numbers:
Svetozar is at station $$$s$$$ and needs to get to station $$$f$$$ ($$$s \ne f$$$). Find the minimum cost of such a trip in coins, using only the circular metro line.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$): the number of test cases. Then, $$$t$$$ test cases follow.
The only line of a test case contains integers $$$n$$$, $$$s$$$, and $$$f$$$ ($$$3 \leq n \leq 10^9$$$, $$$1 \leq s, f \leq n$$$, $$$s \ne f$$$): the number of stations on the line and the starting and ending stations of the trip.
For each test case, print the minimum cost of the trip from station $$$s$$$ to station $$$f$$$ on a separate line.
85 1 56 1 65 1 46 1 43 1 23 3 16 2 367 60 7
213312115
In the first two test cases of the sample, it is cheapest to travel one station counterclockwise. Thus, the cost of the trip is $$$2$$$ coins in the first test case (because the station numbers have the same parity) and $$$1$$$ coin in the second test case (because the parities are different).
In the third test case, Svetozar should travel two stations counterclockwise for $$$2 + 1 = 3$$$ coins.
| Name |
|---|


