#include <bits/stdc++.h>
using namespace std;
const int maxn = 2.5e3;
const int inf = 1e9;
const int mod = 1e9 + 7;
int read() {
  int numm = 0, flagg = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flagg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    numm = numm * 10 + (int)(c - '0');
    c = getchar();
  }
  return flagg * numm;
}
int t, a, b;
int gcd(int aa, int bb) {
  if (aa > bb) swap(aa, bb);
  if (aa == 0) return bb;
  return gcd(bb % aa, aa);
}
int main() {
  t = read();
  while (t--) {
    a = read();
    b = read();
    if (gcd(a, b) == 1)
      printf("Finite\n");
    else
      printf("Infinite\n");
  }
  return 0;
}
