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