#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
void solve() {
  int a, b, x, ans = 0;
  cin >> a >> b;
  while (a != b) {
    int mx, mi;
    mx = max(a, b);
    mi = min(a, b);
    x = ceil(1.0 * (mx - mi) / mi);
    ans += x;
    a < b ? (b = mx - x * mi) : (a = mx - x * mi);
  }
  ans++;
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int test;
  cin >> test;
  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}
