#include <bits/stdc++.h>
using namespace std;
bool isprime(int a) {
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
bool v[10010];
int gcd(int a, int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
int main() {
  int T;
  cin >> T;
  for (int i = 2; i < 10010; i++) {
    v[i] = isprime(i);
  }
  while (T--) {
    int a;
    int b;
    cin >> a >> b;
    if (a == 1 || b == 1) {
      cout << "Finite" << endl;
      continue;
    }
    if (gcd(a, b) == 1) {
      cout << "Finite" << endl;
      continue;
    } else {
      cout << "Infinite" << endl;
      continue;
    }
  }
  return 0;
}
