#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return (gcd(b, a % b));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long p = 0, q = 0, b = 0;
    bool tt = 1;
    cin >> p >> q >> b;
    long long a = q / gcd(p, q);
    if (a == 1) {
      cout << "Finite" << endl;
      continue;
    } else if (b % a == 0) {
      cout << "Finite" << endl;
      continue;
    }
    long long c = gcd(a, b);
    while (gcd(a, c) != 1) {
      c = gcd(a, c);
      a /= c;
    }
    if (a == 1)
      cout << "Finite";
    else
      cout << "Infinite";
    cout << endl;
  }
  return 0;
}
