#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
long long qread() {
  long long w = 1, c, ret;
  while ((c = getchar()) > '9' || c < '0') w = (c == '-' ? -1 : 1);
  ret = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + c - '0';
  return ret * w;
}
long long slv(__int128 a, __int128 b) {
  a = a * a % b, a = a * a % b, a = a * a % b;
  a = a * a % b, a = a * a % b, a = a * a % b;
  return a;
}
int main() {
  for (int T = qread(), END = 1; T >= END; --T) {
    __int128 n = qread(), m = qread(), b = qread();
    puts((__int128)n * slv(b, m) % m ? "Infinite" : "Finite");
  }
  return 0;
}
