#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, c, b;
  int n;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a < b) swap(a, b);
    while (a % b != 0) {
      c = a % b;
      a = b;
      b = c;
    }
    if (b == 1)
      cout << "Finite" << endl;
    else
      cout << "Infinite" << endl;
  }
  return 0;
}
