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