#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 5, MOD = 1e9 + 7;
long long n, a, b;
int main() {
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld%lld", &a, &b);
    long long mn = 1e9 + 9, mx = 0;
    if (a > b)
      mx = a, mn = b;
    else
      mx = b, mn = a;
    long long ans = 0, f = 0;
    while (1) {
      if (mn == mx || mn == 0 || mx == 0) {
        break;
      }
      f = 1;
      long long d = mx;
      ans += d / mn;
      mx = mn;
      mn = d % mn;
    }
    if (f)
      printf("%lld\n", ans);
    else
      printf("1\n");
  }
  return 0;
}
