#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1000][2];
  int count = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    while (a[i][0] != 0 && a[i][1] != 0) {
      if (a[i][0] >= a[i][1]) {
        count += a[i][0] / a[i][1];
        a[i][0] = a[i][0] % a[i][1];
      } else {
        count += a[i][1] / a[i][0];
        a[i][1] = a[i][1] % a[i][0];
      }
    }
    cout << count << endl;
    count = 0;
  }
}
