Under construction

Still being built. Things may change

Maze Escape

Time limit2sMemory limit1024 MB

Summary
Given N rooms in a line, find the fewest teleports to room 1 or room N on a fastest walk from room S to room E.
Level

Medium6 of 10

Topics
Math, Greedy, Implementation
Solved
No attempts yet

Problem

Juwon arrived at a maze while playing an escape room. The maze consists of NN rooms in a row, and room ii is adjacent to room i+1i+1 (1≤i<N1 \leq i < N). Each room has one switch. Juwon starts in room SS, the entrance, presses every switch, and then moves to room EE, the exit, to escape.

Juwon can use two kinds of moves. The first costs 00 and moves to an adjacent room. The second costs 11 and teleports to room 11 or room NN. Both kinds of moves take 1 unit of time each. Pressing a switch takes 0 time.

Escaping requires good time management, so Juwon wants the fastest way out of the maze. Among the ways that escape in the minimum time, find the minimum cost.

Input

The first line contains the number of test cases TT. Each of the following lines gives NN, SS, and EE for one test case, separated by spaces.

Output

For each test case, print the minimum possible cost on one line.

Constraints

  • 1≤T≤1041 \leq T \leq 10^4
  • 2≤N≤1092 \leq N \leq 10^9
  • 1≤S,E≤N1 \leq S, E \leq N
  • S≠ES \neq E
  • All numbers in the input are integers.

Examples1

  1. Example 1

    Input
    3
    5 5 1
    3 1 2
    7 3 5
    
    Expected output
    0
    1
    2