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