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

/**
 * Problem is here: http://www.spoj.com/problems/UCV2013A/
 *
 * I'm not even passing one of the samples here... :(
 */
public class Subtractions {
    private static final long MOD = 1000000007;

    /**
     * Computes base^exp modulo MOD
     *
     * We can write a^b as a summation of a^k where
     * k is a power of two
     * There's only O(log(b)) of these terms
     * Given a^k, computing a^(2k) is as simple as (a^k)^2 
     *
     * That said, I'm willing to bet my bug is in here...
     */
    public static long fastExp(long base, long exp) {
        if (exp == 1) return base;
        long ans = fastExp((base%MOD) * (base%MOD)%MOD, exp / 2);

        if (exp % 2 == 1) {
            ans = (base * ans) % MOD;
        }

        return ans;
    }

    /**
     * Compute the inverse of a mod MOD
     * Only works for prime mods
     * For more information, see
     * https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
     */
    public static long inverse(long a) {
        return fastExp(a, MOD - 2);
    }

    public static long solve(long a, long b) {
        if (a == 0) return 0;
        if (a == b) return 1;
        if (a == 1) return b;
        // assertion: a < b

        long acc = 0;
        acc += b/a;
        long newB = b % a;

        return acc + solve(newB, a);



        /*
        // Answer is N^1 + N^2 + N^3 + ... + N^L
        // Sum               = N^1 + N^2 + N^3 + ... + N^L
        // Sum * N           = N^2 + N^3 + N^4 + ... + N^(L + 1)
        // Sum * N + N       = N + N^2 + N^3 + N^4 + ... + N^(L + 1)
        // Sum * N + N       = Sum + N^(L + 1)
        // Sum * (N - 1) + N = N^(L + 1)
        // Sum               = (N^(L + 1) - N) / (N - 1)

        long numerator = fastExp(N, L + 1) - N;
        // Any time a value can be negative in a mod problem, fix it ASAP
        // For example 3^4 (mod 10) = 1. Subtract 3 to get -2.
        numerator += MOD;
        numerator %= MOD;

        long denominatorInv = inverse(N - 1);

        return (numerator * denominatorInv) % MOD;*/
    }

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bufferedReader.readLine());
        long n = Long.parseLong(st.nextToken());
    while (n-- > 0) {
            st = new StringTokenizer(bufferedReader.readLine());
            long a = Long.parseLong(st.nextToken());
            long b = Long.parseLong(st.nextToken());
            //int L = Integer.parseInt(st.nextToken());
            //if (N == 0 && L == 0) {
            //    break;
            //}
            if (a < b)
                System.out.println(solve(a, b));
            else
                System.out.println(solve(b, a));
        }
    }
}