You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).

You've got some number of pairs (ai, bi). How many operations will be performed for each of them?

Input

The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).

Output

Print the sought number of operations for each pair on a single line.

Examples

Input

2
4 17
7 987654321


Output

8
141093479
num_pairs = int(input())

arr = []

for pair in range(num_pairs):
   operations = 0
   val = input().split(" ")
   lesser_num = int(val[0]) if int(val[0]) < int(val[1]) else int(val[1])
   greater_num = int(val[1]) if int(val[0]) <= int(val[1]) else int(val[0])
   while (greater_num > 0 and lesser_num > 0):
      difference = (greater_num - lesser_num)
      difference = difference//lesser_num + 1
      operations += difference
      greater_num = greater_num - difference*lesser_num
      temp = lesser_num
      lesser_num = greater_num
      greater_num = temp
   arr.append(operations)

for val in range(len(arr)):
   print(str(arr[val]))