#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 11;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    while (a > 0 && b >> 0) {
      int bigger = max(a, b);
      int smaller = min(a, b);
      ans += bigger / smaller;
      a = bigger % smaller;
      b = smaller;
    }
    cout << ans << endl;
  }
  return 0;
}
