#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int T;
  cin >> T;
  while (T--) {
    int a, b;
    cin >> a >> b;
    if (b < a) swap(a, b);
    if (a == 1) {
      cout << "Finite" << endl;
      continue;
    }
    vector<bool> remains(a, false);
    remains[0] = 1;
    for (int i = 1; i < a; ++i) remains[(i * b) % a] = true;
    bool result = 1;
    for (auto a : remains) result = result & a;
    if (result)
      cout << "Finite" << endl;
    else
      cout << "Infinite" << endl;
  }
  return 0;
}
