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
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323;
const long long mod1 = 1e9 + 7;
const long long mod2 = 1e18;
const long long mod3 = 9e18;
long long power(long long x, long long n) {
  if (n == 0) return 1;
  long long temp = power(x, n / 2);
  if (n % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
long long gcd(long long a, long long b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); }
void swap(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
bool f(long long x, long long y) { return x > y; }
long long MAX(long long a, long long b) { return a > b ? a : b; }
long long MIN(long long x, long long y) { return x > y ? y : x; }
long long MAX(long long a, long long b, long long c) {
  return MAX(a, MAX(b, c));
}
long long MIN(long long a, long long b, long long c) {
  return MIN(a, MIN(b, c));
}
long long pmod(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return ans;
}
bool cmp2(pair<long long, long long>& a, pair<long long, long long>& b) {
  return a.second > b.second;
}
bool isPrime(long long num) {
  bool flag = true;
  for (long long i = 2; i <= num / 2; i++) {
    if (num % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
void solve() {
  long long x, y;
  cin >> x >> y;
  if (x < y) swap(x, y);
  long long ans = 0;
  while (x && y) {
    ans += x / y;
    x %= y;
    swap(x, y);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
