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.util.*;
import java.io.*;
import java.lang.Math.*;

public class subtractions
{
	public static void main(String[] args) {
         Scanner infile = new Scanner(System.in);
         PrintStream outfile = new PrintStream(System.out);

         int cases = infile.nextInt();
         for(int i = 0; i < cases; i++)
         {
         	long firstVal = infile.nextInt();
         	long secondVal = infile.nextInt();
         	//need to use modulus ioperations here!!!

         	long result = computeSubs(firstVal,secondVal,0);
         	//long result = computeCases(firstVal,secondVal,0);
         	System.out.println(result);
         }

	}

	//look up peano sutraction magic!!
	public  static long computeSubs(long x, long y, long result)
	{

		if(x > 0 && y > 0)
		{

			if(x > y)
			{
				//return computeSubs((x/y), (x%y), result += (x/y));
				return computeSubs(x - ((x/y) * y), y, result += (x/y));
			}
			else if (x < y)
			{
				return computeSubs(x,y - ((y/x) * x), result += (y/x));
				//return computeSubs((y/x), (y%x), result += (y/x));
			}
			else
				return result + 1; //you know you are done here (see case of (5,5))
		}
		else
			return result;
	}

	//apply tail recursion here
	//this will fail as it causes an overflow error!!!
	public static long computeCases(long x, long y, long result)
	{
		if(x > 0 && y > 0)
		{
			// System.outfile.println()
			if(x>y) 
				return computeCases(x-y,y,result+1);
			else if(x < y)
				return	computeCases(x,y-x,result+1);
			else
				return computeCases(x-y,y,result+1);
		}
		else
			return result;

	}
}