#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int r;
  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, i, j, h;
    cin >> n >> m;
    if (n == 1 || m == 1 || gcd(n, m) == 1) {
      cout << "Finite" << endl;
    } else {
      cout << "Infinite" << endl;
    }
  }
}
