#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 4;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool check(long long a, long long b) {
  if (a == 1) return true;
  long long tmp = gcd(a, b);
  if (tmp == 1) return false;
  return check(a / tmp, tmp);
}
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    long long p, q, b;
    scanf("%lld%lld%lld", &p, &q, &b);
    long long g = gcd(p, q);
    p = p / g;
    q = q / g;
    if (check(q, b))
      puts("Finite");
    else
      puts("Infinite");
  }
}
