#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long int x, y;
    cin >> x >> y;
    long long int sum = 0;
    while (x > 0 && y > 0) {
      if (x > y) {
        sum += x / y;
        x = x % y;
      } else {
        sum += y / x;
        y = y % x;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
