#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, k;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    k = 0;
    while (b) {
      if (b < a) swap(a, b);
      k += b / a;
      b %= a;
    }
    cout << k << endl;
  }
}
