#include <bits/stdc++.h>
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); }
int f(long long x, long long y, long long z) {
  if (x == 0) {
    return 1;
  };
  long long g;
  long long t = y / gcd(x, y);
  while (t > 1) {
    g = gcd(t, z);
    if (g == 1) break;
    while (t % g == 0) {
      t /= g;
    };
  };
  return (t == 1) ? 1 : 0;
};
using namespace std;
int main() {
  long long n, b, q, p;
  n = read();
  for (int i = 1; i < n + 1; i++) {
    p = read();
    q = read();
    b = read();
    if (f(p, q, b) == 1) {
      cout << "Finite" << endl;
    } else {
      cout << "Infinite" << endl;
    }
  }
  return 0;
}
