#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, k;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  while (n--) {
    cin >> a >> b >> k;
    b /= gcd(a, b);
    long long t = gcd(b, k);
    while (t > 1) {
      while (b % t == 0) b /= t;
      t = gcd(b, k);
    }
    if (b == 1)
      cout << "Finite\n";
    else
      cout << "Infinite\n";
  }
  return 0;
}
