#include <bits/stdc++.h>
using namespace std;
int n;
unsigned long long a, b, k;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  unsigned long long s = 1, c;
  while (a && b) {
    if ((~a & 1) && (~b & 1))
      a >>= 1, b >>= 1, s <<= 1;
    else if (~a & 1)
      a >>= 1;
    else if (~b & 1)
      b >>= 1;
    else if (a > b)
      a = a - b;
    else
      c = b - a, b = a, a = c;
  }
  if (!a) return b * s;
  if (!b) return a * s;
}
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%lld%lld%lld", &a, &b, &k);
    b /= gcd(a, b);
    unsigned 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;
}
