#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  int N;
  scanf("%d", &N);
  long long P, Q, B;
  for (int n = int(0); n < int(N); ++n) {
    scanf("%I64d %I64d %I64d", &P, &Q, &B);
    long long c = gcd(P, Q);
    Q /= c;
    c = gcd(Q, B);
    while (c > 1) {
      while (Q % c == 0) Q /= c;
      c = gcd(Q, B);
    }
    if (Q > 1)
      printf("Infinite\n");
    else
      printf("Finite\n");
  }
  return 0;
}
