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 long M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
long long modPow(long long a, long long b) {
  if (b == 0) return 1LL;
  if (b == 1) return a % M;
  long long res = 1;
  while (b) {
    if (b % 2 == 1)
      res = mul(res, a), b--;
    else
      a = mul(a, a), b = b / 2;
  }
  return mod(res);
}
const long long N = 2e5 + 2;
long long fact[N];
void precalc() {
  fact[0] = 1;
  for (long long i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
}
long long inv(long long x) { return modPow(x, M - 2); }
long long divide(long long a, long long b) { return mul(a, inv(b)); }
long long nCr(long long n, long long r) {
  return divide(fact[n], mul(fact[r], fact[n - r]));
}
long long factorial(long long n) {
  long long fact = 1;
  for (long long i = 1; i <= n; ++i) {
    fact *= i;
  }
  return fact;
}
void solve() {
  long long a, b;
  cin >> a >> b;
  long long res = 0;
  while (1) {
    if (b > a) swap(a, b);
    res += a / b;
    a -= (b * (a / b));
    if (a == 0) break;
    res += b / a;
    b -= (a * (b / a));
    if (b == 0) break;
  }
  cout << res << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
