#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    while (a > 0 && b > 0) {
      if (max(a, b) % min(a, b) == 0) {
        ans += max(a, b) / min(a, b);
        a = 0;
      } else {
        int f = (max(a, b) / min(a, b)) - 1;
        int c = max(a, b);
        int d = min(a, b);
        if (f > 0) {
          c = d + c % d;
        } else {
          c %= d;
          ans++;
        }
        ans += f;
        a = c;
        b = d;
      }
    }
    cout << ans << endl;
  }
}
