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