#include <bits/stdc++.h>
using namespace std;
int n;
long long p, q, b, d;
long long NWD(long long a, long long b) {
  while (b != 0) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
bool finite(long long q, long long b) {
  if (b % q == 0) return true;
  long long d = NWD(q, b);
  while (d != 1) {
    while (q % d == 0) q = q / d;
    d = NWD(b, q);
  }
  return (q == 1);
}
int main() {
  std::ios_base::sync_with_stdio(0);
  cin >> n;
  while (n-- > 0) {
    cin >> p >> q >> b;
    d = NWD(p, q);
    p = p / d;
    q = q / d;
    if (finite(q, b))
      cout << "Finite\n";
    else
      cout << "Infinite\n";
  }
}
