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.*;
public class Subtractions 
{
	public static class Pair
	{
		public int a;
		public int b;
		public Pair(int a, int b)
		{
			this.a = a;
			this.b = b;
		}
		
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + a;
			result = prime * result + b;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (a != other.a)
				return false;
			if (b != other.b)
				return false;
			return true;
		}
		
		
	}
	public static void main (String args[])
	{
		Scanner input = new Scanner(System.in);
		int num = input.nextInt();
		HashMap<Pair, Integer> cache = new HashMap<Pair, Integer>();
		
		for (int i = 0; i < num; i++)
		{
			int a = input.nextInt();
			int b = input.nextInt();
			int sol;
			Pair pair = new Pair(a, b);
			if (cache.containsKey(pair))
			{
				sol = cache.get(pair);
			}
			else
			{
				sol = ops(a, b);
			}
			System.out.println(sol);
		}
	}
	
	public static int ops(int a, int b, HashMap<Pair, Integer> cache)
	{
		if (a > 0 && b > 0)
		{
			if (a == b)
			{
				int sol = 1 + ops(a, a - b, cache);
				cache.put(new Pair(a, b), sol);
				return sol;
			}
			else if (a < b)
			{
				int sol = 1 + ops(a, b - a, cache);
				cache.put(new Pair(a, b), sol);
				return sol;
			}
			else
			{
				int sol = 1 + ops(a - b, b, cache);
				cache.put(new Pair(a, b), sol);
				return sol;
			}
		}
		return 0;
	}
	
	public static int ops(int a, int b)
	{
			int count = 0;
			while (a > 0 && b > 0)
			{
				if (a == b)
				{
					b = a - b;
					count++;
				}
				else if (a < b)
				{
					int div = b/a;
					b = b - (div * a);
					count += div;
				}
				else
				{
					int div = a/b;
					a = a - (div * b);
					count += div;
				}
			}
			return count;
	}
}
