#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b;
  cin >> t;
  while (t--) {
    long long count = 0;
    cin >> a >> b;
    for (int i = 0;; i++) {
      if (b == 0 || a == 0) {
        break;
      }
      if (a > b) {
        long long temp = a;
        a = b;
        b = temp;
      }
      if (b >= a) {
        count += (b / a);
        b = b - ((b / a) * a);
      }
    }
    cout << count << endl;
  }
  return 0;
}
