#include <bits/stdc++.h>
int main() {
  long n, k, a, b;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a >> b;
    k = 0;
    while (a != 0 && b != 0) {
      if (a < b) {
        long temp = a;
        a = b;
        b = temp;
      }
      long q = a / b;
      k += q;
      a = a - q * b;
    }
    std::cout << k << std::endl;
  }
  return 0;
}
