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