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
import java.io.*;
import java.util.*;

//reduces larger of a and b by the value of the other, and repeats.
//prints # of times either # was reduced.
public class Subtractions {
	public static void main(String[] args) throws IOException {
		final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(br.readLine());
		StringTokenizer st;
	    StringBuilder out = new StringBuilder();
		
		for (int i = 0; i < n; i++) {
			st = new StringTokenizer(br.readLine());
			int tally = 0;
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			//sort such that a >= b
			if(a < b) {
				int c = a;
				a = b;
				b = c;
			}
			while(b > 0) {
				int k = (a - b) / b + 1;
				tally += k;
				a -= b * k;
				//swap so a >= b
				k = a;
				a = b;
				b = k;
			}
			out.append(tally);
			out.append('\n');
		}
		//check prev at the very end again
		
		System.out.println(out.toString());
	}
}
