#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a, b, ans;
  scanf("%d", &t);
  while (t--) {
    ans = 0;
    scanf("%d %d", &a, &b);
    while (a > 0 && b > 0) {
      if (a >= b) {
        ans += (a / b);
        a = a % b;
      } else if (b > a) {
        ans += (b / a);
        b = b % a;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
