#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 998244353;
const int N = 2e5 + 2;
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    set<int> aa, bb;
    for (int i = 2; i * i <= a; i++) {
      if (a % i == 0) {
        aa.insert(i);
        while (a % i == 0) a /= i;
      }
    }
    if (a > 1) aa.insert(a);
    for (int i = 2; i * i <= b; i++) {
      if (b % i == 0) {
        bb.insert(i);
        while (b % i == 0) b /= i;
      }
    }
    if (b > 1) bb.insert(b);
    bool ok = 1;
    for (auto& i : aa) {
      if (bb.count(i)) ok = 0;
    }
    puts(ok ? "Finite" : "Infinite");
  }
  return 0;
}
