#include <bits/stdc++.h>
using namespace std;
int T, cnt = 0;
long long a, b, c;
long long yz[1000000];
long long gcd(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%lld%lld%lld", &a, &b, &c);
    a = a % b;
    if (a == 0) {
      printf("Finite\n");
      continue;
    }
    long long t = gcd(a, b);
    b /= t;
    long long k = gcd(b, c);
    cnt = 0;
    for (long long i = 2; i * i <= k; i++) {
      if (k % i == 0) {
        yz[++cnt] = i;
        while (k % i == 0) k /= i;
      }
    }
    if (k != 1) yz[++cnt] = k;
    for (int i = 1; i <= cnt; i++)
      while (b % yz[i] == 0) b /= yz[i];
    if (b != 1)
      printf("Infinite\n");
    else
      printf("Finite\n");
  }
  return 0;
}
