#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
vector<long long> q;
long long compute_log(long long a, long long b) {
  long long ctr = 0;
  if (b == 1) {
    return LLONG_MAX;
  }
  while (a > 0) {
    a /= b;
    ctr++;
  }
  return ctr;
}
map<long, long> generate_prime_factors(long long n) {
  map<long, long> factors;
  while (n % 2 == 0) {
    if (factors.find(2) != factors.end()) {
      factors[2]++;
    } else {
      factors[2] = 1;
    }
    n /= 2;
  }
  for (long long i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      if (factors.find(i) != factors.end()) {
        factors[i]++;
      } else {
        factors[i] = 1;
      }
      n /= i;
    }
  }
  if (n > 2) {
    factors[n] = 1;
  }
  return factors;
}
long long totient(long long n) {
  map<long, long> primes = generate_prime_factors(n);
  long long t = 1;
  for (auto p : primes) {
    t *= (long long)powl(p.first, p.second - 1) * (p.first - 1);
  }
  return t;
}
void print_lms(multiset<long long> s) {
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << *it << " ";
  }
  cout << "\n";
}
void print_ls(set<long long> s) {
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << *it << " ";
  }
  cout << "\n";
}
long long modpow(long long x, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modpow(x, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * x) % m;
  return u;
}
void blockmax(long long d, long long *x, long long *ans, long long n) {
  int q1 = 0, q2 = 0;
  for (int i = 0; i < n; i++) {
    while (q1 > q2 && x[q[q1 - 1]] <= x[i]) q1--;
    q[q1++] = i;
    if (i >= d && q[q2] == i - d) q2++;
    if (i >= d - 1) {
      ans[i - (d - 1)] = x[q[q2]];
    }
  }
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0;
    *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
void solve() {
  long long a, b;
  cin >> a >> b;
  long long x, y;
  long long g = gcdExtended(a, b, &x, &y);
  if (g == 1) {
    cout << "Finite\n";
  } else {
    cout << "Infinite\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  for (int t = 1; t <= tc; t++) {
    solve();
  }
}
