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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
 
public class Main 
{
    static ArrayList<Integer> ar=new ArrayList<>();
    static long fAns;
    static long fact(long j)
    {
        if(j==1)
        return 1;
        return j*fact(j-1);
    }
    static int gcd(int a,int b)
    {
        if(a==0)
        return b;
        return gcd(b%a,a);
    }
    static void f1(long a,long b)
    {
        
        fAns+=b/a;
        if(b%a==0)
        return;
        
        
        if(b%a>0)
        f1(b%a,a);
        
    }
    static long noOfDivisors(long n)
    {
        long ans=0l;
        if(n%2==0)
        ans++;
        while(n%2==0)
        {
            n/=2;
        }
        
        for(int i=3;i<=Math.sqrt(n);i+=2)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                ans++;
            }
        }
        if(n>2)
        ans++;
        return ans;
    }
    static void seive()
    {
        int i,j;
        boolean a[]=new boolean[32001];
        for(i=2;i<=Math.sqrt(32000);i++)
        {
            for(j=i*i;j<=32000;j+=i)
            a[j]=true;
        }
        for(i=2;i<=32000;i++)
        if(!a[i])
        ar.add(i);
    }
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int T=fs.nextInt();
		int i,j,k,n;
        // int T=1;
        long ans=0l,max=0l;
        seive();
		for (int tt=0; tt<T; tt++) 
		{
// 			n=fs.nextInt();
			ans=fs.nextLong();
			max=fs.nextLong();
			fAns=0l;
			f1(ans,max);
            System.out.println(fAns);
		}
	}
 
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
 
	
}