#include <bits/stdc++.h>
using namespace std;
long long gcddd(long long a, long long b) {
  long long c(0), t(0);
  while (a != b && a != 0 && b != 0) {
    if (a > b) {
      t = a / b;
      c += t;
      a = a - (t * b);
    } else {
      t = b / a;
      c += t;
      b = b - (t * a);
    }
  }
  return c;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long c = gcddd(a, b);
    a == b ? cout << 1 << endl : cout << c << endl;
  }
}
