#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
int main() {
  int n;
  long long a, b;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    long long res = 0;
    while (a && b) {
      if (a == b) {
        res++;
        break;
      }
      if (a > b) swap(a, b);
      long long diff = b - a;
      if (diff / a)
        res += (diff / a), b -= a * (diff / a);
      else
        res++, b -= a;
    }
    cout << res << endl;
  }
}
