#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    long long count = 0;
    while (a != 0 && b != 0) {
      if (a > b) {
        count += a / b;
        a = a % b;
      } else if (b > a) {
        count += b / a;
        b = b % a;
      } else
        break;
    }
    if (count != 0)
      cout << count << '\n';
    else
      cout << "1\n";
  }
  return 0;
}
