#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int 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 << endl;
  }
  return 0;
}
