LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DPDigit DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Monopoly

Super EasyProblem #12
Time LimitMemoryInputOutput
0.1 s64 MBstdinstdout

Monopoly is a game in which players move over fields arranged in a circle, always in the clockwise direction. The fields are numbered 0 to n−1, both players start the game on field 0 and never move backwards. If we know the total number of fields each player has traveled since the start of the game, we also know where each of them stands right now.

Your task is to compute how many steps forward the first player has to make to land on the field where the second player is standing.

Input

First line of input will be a single integer t - the number of testcases.
Each of the next t lines contains three integers n, a and b - the number of fields on the board, the total number of fields the first player has traveled, and the total number of fields the second player has traveled since the start of the game.

Output

For every testcase print a single line with the number of steps forward the first player has to make to reach the field the second player is standing on.

Example

Input
2
10 3 7
10 7 3
Output
4
6

In the first testcase the players stand on fields 3 and 7, so 4 steps are enough. In the second the first player stands on field 7 and the second on field 3 - moving forward he passes fields 8,9,0,1,2 and lands on 3, which is 6 steps.

Constraints

1≤t≤10
1≤n≤109
0≤a,b≤109


This problem was adapted, with permission, from Monopol, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit