#include <bits/stdc++.h>
int gcd(int a, int b) {
  while (a != b) {
    if (a > b) {
      return gcd(a - b, b);
    } else {
      return gcd(a, b - a);
    }
  }
  return a;
}
int main() {
  int t;
  int a, b;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (a == 1 || b == 1) {
      printf("Finite\n");
    } else {
      if (gcd(a, b) != 1)
        printf("Infinite\n");
      else
        printf("Finite\n");
    }
  }
  return 0;
}
