#include <bits/stdc++.h>
using namespace std;
long long substractions(long long a, long long b) {
  long long z = max(a, b) % min(a, b);
  if (z == 0) return (max(a, b) / min(a, b));
  return substractions(min(a, b), z) + (max(a, b) / min(a, b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b, t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    cin >> a >> b;
    cout << substractions(a, b) << endl;
  }
  return 0;
}
