Nano's clock hands
Time limit1sMemory limit1024 MB
Two clocks with N and M ticks have hands moving in opposite directions, and the task asks for the first positive second when both hands point to the same number.
- Level
Medium7 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
Inside Nano's head, two small clocks are running. Clock A has ticks through drawn in clockwise order, and clock B has ticks through drawn the same way. Each hand moves one tick per second. Hand A turns counterclockwise, and hand B turns clockwise.

Right now, both hands point to . Find the earliest time, in seconds, at which the two hands point to the same integer again.
Input
The first line contains the number of test cases ().
Each test case is given as two integers and ().
Output
For each test case, print the answer on its own line.