#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, y, m, cnt;
  cin >> t;
  while (t--) {
    cin >> x >> y;
    cnt = 0;
    while (y && x) {
      m = x > y ? x : y;
      y = x < y ? x : y;
      cnt += m / y;
      x = m % y;
    }
    cout << cnt << endl;
  }
  return 0;
}
