#include <bits/stdc++.h>
using namespace std;
int main() {
  int testCase;
  cin >> testCase;
  long long a, b, count;
  for (int i = 0; i < testCase; i++) {
    count = 0;
    cin >> a >> b;
    while (a > 0 && b > 0) {
      if (a == b) {
        count++;
        break;
      } else if (a > b) {
        count += a / b;
        a = a % b;
      } else {
        count += b / a;
        b = b % a;
      }
    }
    cout << count << endl;
  }
  return 0;
}
