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.*;

public class First {
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter pw = new PrintWriter(System.out);
    private static StringBuffer ans = new StringBuffer();

    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            ans.append(count(sc.nextInt(), sc.nextInt()));
            ans.append('\n');
        }
        pw.print(ans);
        sc.close();
        pw.close();
    }

    private static int count(int a, int b) {
        int c = 0;
        while (a > 0 && b > 0) {
            if (a < b) {
                c += (b / a);
                b -= ((b / a) * a);
            } else {
                c += (a / b);
                a -= ((a / b) * b);
            }
        }
        return c;
    }
}

class Scanner {
    private final BufferedReader br;
    private StringTokenizer st;

    public Scanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(in));
        st = new StringTokenizer("");
    }

    public String next() throws IOException {
        if (!st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public void close() throws IOException {
        br.close();
    }
}

class PrintWriter {
    private final BufferedOutputStream pw;

    public PrintWriter(OutputStream out) {
        pw = new BufferedOutputStream(out);
    }

    public void print(Object o) throws IOException {
        pw.write(o.toString().trim().getBytes());
        pw.flush();
    }

    public void close() throws IOException {
        pw.close();
    }
}