#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  int n;
  scanf("%d", &n);
  long long p, q, b;
  while (n--) {
    scanf("%lld%lld%lld", &p, &q, &b);
    long long t = gcd(p, q);
    p /= t;
    q /= t;
    if (p == 0)
      puts("Finite");
    else {
      while (b % q) {
        long long g = gcd(b, q);
        if (g == 1) break;
        b = g;
        q /= g;
      }
      if (b % q == 0)
        puts("Finite");
      else
        puts("Infinite");
    }
  }
  return 0;
}
