This page is still under construction.

Parts of this page are still being built. What you see may change.

Chasing

Interview

Time limit1sMemory limit256 MB

Summary
Compute how many turns pass until a tortoise moving one section per turn and a hare moving two meet on a circular track.
Level

Medium5 of 10

Topics
Math
Solved
No attempts yet

Problem

A tortoise and a hare chase each other on a circular track made of NN sections. The sections are numbered 1,2,…,N1, 2, \dots, N, and section 11 comes right after section NN. The track is one way. From section ii the only move is to section i+1i+1, and from section NN the only move is to section 11.

When the race starts, the hare is on section RR and the tortoise is on section TT. A turn begins with the tortoise, which moves forward one section, and then the hare moves forward two sections. The race ends the moment both animals are on the same section, which can happen before the hare has finished its two sections. One turn counts the tortoise's move and the hare's move together. If the two are already on the same section before anyone moves, the race ends at once and takes 00 turns.

Given the size of the track and the two starting sections, write a program that finds how many turns the race takes.

Input

The first line has the number of test cases KK (1≤K≤100,0001 \le K \le 100{,}000).

Each of the next KK lines has three integers NiN_i, RiR_i, TiT_i (1≤Ni≤10181 \le N_i \le 10^{18}, 1≤Ri,Ti≤Ni1 \le R_i, T_i \le N_i): the size of the track, the hare's starting section, and the tortoise's starting section of the ii-th test case.

Output

Print KK lines. The ii-th line has the number of turns the ii-th test case takes.

Examples2

  1. Example 1

    Input
    4
    10 1 4
    10 8 3
    10 2 10
    20 5 5
    
    Expected output
    3
    5
    8
    0
    
  2. Example 2

    Input
    4
    1 1 1
    2 1 1
    2 1 2
    2 2 1
    
    Expected output
    0
    0
    1
    1