#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, k;
long long gcd(long long a, long long b) {
  while (b ^= a ^= b ^= a %= b)
    ;
  return a;
}
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%lld%lld%lld", &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)
      printf("Finite\n");
    else
      printf("Infinite\n");
  }
  return 0;
}
