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