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