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