SPEED - Circular Track

Two persons are running on a circular track either in the same direction or in the opposite direction, indefinitely. The speed of both of them is given to you. Speed will be positive in clockwise direction, and negative in anticlockwise direction. Print the number of distinct points, at which they will meet on the circle.

Input

First line contains T, number of test cases. Each test case contains two integers, S1 and S2 (not equal to zero) which are the speeds of the two persons. S1 and S2 will be distinct.

Edited: All the numbers fit in signed 32-bit integer.

Output

Print in a separate line, the number of distinct points at which they meet.

Example

Input
2
1 2
1 -1

Output
1
2

Added by:Nikunj Jain
Date:2011-07-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2015-06-25 13:47:41
math, math and math + Euclidean algorithm for gcd
2015-06-17 15:22:22 AMIT KUMAR YADAV
SPEED THRILLS ;P
2015-04-27 10:12:25 _R0b_
hint - gcd
2014-10-29 12:49:30 Ashish Sareen
Cool One!!
2014-05-25 21:37:23 humblefool_2
I dont understand the test cases..what does "meet at distinct points mean"?
2014-01-31 00:21:15 Omar ِAlsherbini
I think the question should have told us more about the type of the variables, S1 and S2.
2013-10-30 02:57:25 harshil sukhadia
i think something is missing because if they run indefinitely and have distinct speeds than they will meet infinite times...??
2013-08-19 20:42:23 nsaini
getting WA
pls check my code <snip>

Last edit: 2023-05-24 20:21:07
2013-05-09 07:06:06 ওয়াসী (Wasi)
solved it with 0.10 run time on python 3.2.3
thanks for all the testcases specially @saket diwakar
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.