#include <bits/stdc++.h>
using namespace std;
int n, cnt;
int x, y;
int main() {
  scanf("%d", &n);
  while (n--) {
    cnt = 0;
    scanf("%d %d", &x, &y);
    while (true) {
      if (x >= y) {
        cnt = cnt + x / y;
        x = x % y;
      } else {
        cnt = cnt + y / x;
        y = y % x;
      }
      if (x == 0 || y == 0) break;
    }
    printf("%d\n", cnt);
  }
  return 0;
}
