#include <bits/stdc++.h>
const long long int INF = 1000 * 1000 * 1000;
const int MAXN = 1000 * 1000;
using namespace std;
int n, a, b, i, ans;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    ans = 0;
    cin >> a >> b;
    while (a > 0 && b > 0) {
      if (b > a) swap(a, b);
      ans += a / b;
      a %= b;
    }
    cout << ans << endl;
  }
  return 0;
}
