#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int res = 0;
    int a;
    int b;
    cin >> a >> b;
    while (a != 0 and b != 0) {
      if (a > b) {
        res = res + a / b;
        a = a % b;
      } else {
        res = res + b / a;
        b = b % a;
      }
    }
    cout << res << endl;
  }
}
