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 Codechef {
    
    PrintWriter out;
    InputStream is;

    boolean isprime[];
    List <Integer> primes = new Vector<>();
    void sieveOfEratosthenes() {
    	isprime = new boolean[30000];
    	for (int i = 0; i < 30000; ++i) {
    		isprime[i] = true;
    	}
    	isprime[0] = false;
    	isprime[1] = false;
    	for (int i = 2; i * i < 30000; ++i) {
    		if(isprime[i]) {
    			for (int j = i*i; j < 30000; j += i) {
    				isprime[j] = false; 	
    			}
    		}
    	}
    	for (int i = 2; i < 10000; ++i) {
    		if(isprime[i])
    			primes.add(i);
    	}
    }

    void solve() {
    	int t = ni();
    	while(t-- != 0) {
    		int a = ni(), b = ni();
    		int ans = 0;
    		while(a != 0 && b != 0) {
    			if(a < b) {
    				ans += b/a;
    				b = b % a;
    				// if(b == 0) break;  
    			} else {
    				ans += a/b;
    				a = a % b;
    				// if(a == 0) break;
    			}
    		}
    		out.println(ans);
    	}
    }

    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    
    public static void main(String[] args) {
        new Codechef().run();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;
   
    int readByte() { 
        if(ptr >= len) { ptr = 0; 
            try { len = is.read(input); } 
            catch(IOException e) { throw new InputMismatchException(); } 
            if(len <= 0) { return -1; } 
        } return input[ptr++];
    }
    
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    
    int skip() { 
        int b = readByte(); 
        while(b != -1 && isSpaceChar(b)) { b = readByte(); } 
        return b;
    }
    
    char nc() { return (char)skip(); }
    
    String ns() { 
        int b = skip(); 
        StringBuilder sb = new StringBuilder(); 
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } 
        return sb.toString();
    }
    
    String nLine() { 
        int b = skip(); 
        StringBuilder sb = new StringBuilder(); 
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } 
        return sb.toString();
    }
    
    int ni() { 
        int n = 0, b = readByte(); 
        boolean minus = false; 
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } 
        if(b == '-') { minus = true; b = readByte(); } 
        if(b == -1) { return -1; }  //no input 
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } 
        return minus ? -n : n;
    }
    
    long nl() { 
        long n = 0L;    int b = readByte(); 
        boolean minus = false; 
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } 
        if(b == '-') { minus = true; b = readByte(); } 
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } 
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    
    float nf() { return Float.parseFloat(ns()); }
    
    int[] na(int n) { 
        int a[] = new int[n]; 
        for(int i = 0; i < n; i++) { a[i] = ni(); } 
        return a;
    }

    char[] ns(int n) { 
        char c[] = new char[n]; 
        int i, b = skip(); 
        for(i = 0; i < n; i++) { 
            if(isSpaceChar(b)) { break; } 
            c[i] = (char)b; b = readByte(); 
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}