#include <bits/stdc++.h>
int gcd(int a, int b) {
  if (a > b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  if (b % a == 0) return a;
  return gcd(b % a, a);
}
int main() {
  int T, tc, n, k, d, l, r, tans, ans, sum, m, tgt;
  register int i;
  scanf("%d", &T);
  for (tc = 1; tc <= T; tc++) {
    scanf("%d %d", &n, &k);
    if (gcd(n, k) == 1)
      printf("Finite\n");
    else
      printf("Infinite\n");
  }
}
