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.math.BigInteger;
import java.util.*;
 
 
public class Main {
	static HashSet<Integer> set=new HashSet<Integer>();
	static int count=0;
	static int citi=0;
		public static void main(String[] args) throws IOException 
		{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);
//int n=in.nextInt();
/*BST b=new BST();
Node root=b.NewNode(1);
root.left=b.NewNode(2);
root.right=b.NewNode(3);
root.left.left=b.NewNode(4);
root.left.left.left=b.NewNode(5);
root.left.left.left.left=b.NewNode(6);
root.left.right=b.NewNode(7);
root.left.right.right=b.NewNode(8);
root.left.right.right.right=b.NewNode(9);
//System.out.println(b.Diameter(root));
b.PrintAncestors(root, 7);*/
      int q=in.nextInt();
      while(q-->0)
      {
    	  int ans=0;
    	  int a=in.nextInt();
    	  int b=in.nextInt();
    	  while(a!=0&&b!=0)
    	  {
    		  if(a<b)
    		  {
    			  int t=a;
    			  a=b;
    			  b=t;
    		  }
    		  ans+=(a/b);
    		  a%=b;
    	  }
    	  System.out.println(ans);
    	  
      }
		
}
public static void dfs(int s,ArrayList<Integer> adj[],boolean visited[])
{
	visited[s]=true;
	//count++;
	for(int i=0;i<adj[s].size();i++)
	{
		if(!visited[adj[s].get(i)])
			count++;
	}
	for(int i=0;i<adj[s].size();i++)
	{
		if(!visited[adj[s].get(i)])
		{
		citi++;	
            dfs(adj[s].get(i),adj,visited);
		}
	}
	
}
		public static long power(long a,long b)
		{
			long result=1;
			while(b>0)
			{
				if(b%2==1)
					result*=a;
				a=a*a;
				b/=2;
			}
			return result;
		}
				public static long pow(long n,long p,long m)
	{
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	}
	static class Pair implements Comparable<Pair>{
		int val;
		int fr;
		Pair(int mr,int er){
			val=mr;
			fr=er;
			
		}
		@Override
		public int compareTo(Pair o) {
			return 1;
			}
	}
	public static long gcd(long a, long b) {
		  if (b == 0) return a;
		  return gcd(b, a%b);
		}
	static class InputReader {
 
		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
 
		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public   int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}