#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, Sum = 0;
    cin >> a >> b;
    if (a < b) swap(a, b);
    while (b != 0) {
      Sum += a / b;
      a %= b;
      if (a < b) swap(a, b);
    }
    cout << Sum << "\n";
  }
}
