#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, maxi, mini, ans = 0;
    cin >> a >> b;
    maxi = max(a, b);
    mini = min(a, b);
    while (mini > 0) {
      ans += (maxi / mini);
      maxi -= ((maxi / mini) * mini);
      swap(maxi, mini);
    }
    cout << ans << endl;
  }
}
