#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int a, b;
    int max;
    int min;
    cin >> a >> b;
    if (a > b) {
      max = a;
      min = b;
    } else {
      max = b;
      min = a;
    }
    if (a == 1 || b == 1) {
      cout << "Finite" << endl;
      continue;
    }
    int res;
    do {
      res = min;
      min = max % min;
      max = res;
    } while (min != 0);
    if (res == 1) {
      cout << "Finite" << endl;
    } else {
      cout << "Infinite" << endl;
    }
  }
  return 0;
}
