#include <bits/stdc++.h>
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long INFLL = 1e18;
const double PI = acos((double)-1);
inline int mult(int a, int b, int p = MOD) { return (1ll * a * b) % p; }
inline int add(int a, int b, int p = MOD) { return (1ll * a + b) % p; }
inline int fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    while (x != y && x > 0 && y > 0) {
      if (x > y) {
        int p = x / y;
        x -= p * y;
        ans += p;
      } else {
        int p = y / x;
        y -= p * x;
        ans += p;
      }
    }
    if (x == y)
      cout << ans + 1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
