#include <bits/stdc++.h>
using namespace std;
int hcf(int x, int y) {
  if (y != 0)
    return hcf(y, x % y);
  else
    return x;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (hcf(a, b) == 1)
      cout << "finite" << endl;
    else
      cout << "infinite" << endl;
  }
}
