#include <bits/stdc++.h>
using namespace std;
int main() {
  int _testcases, i, j, count = 0;
  cin >> _testcases;
  for (int m = 0; m < _testcases; m++) {
    cin >> i >> j;
    while (i != 0 && j != 0) {
      if (i < j) {
        int temp = i;
        i = j;
        j = temp;
      }
      if (i % j == 0) {
        count += (i / j);
        i = 0;
      } else {
        int n = i / j;
        i = i - (j * n);
        count += n;
      }
    }
    cout << count << endl;
    count = 0;
  }
  return 0;
}
