#include <bits/stdc++.h>
using namespace std;
int n;
long long gcd(long long x, long long y) { return (y ? gcd(y, x % y) : x); }
bool pan(long long x, long long y) {
  while (x != 1) {
    long long z = gcd(x, y);
    if (z == 1) return false;
    while (x % z == 0) x /= z;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    long long x, y, z;
    scanf("%I64d%I64d%I64d", &x, &y, &z);
    long long Gcd = gcd(x, y);
    x /= Gcd;
    y /= Gcd;
    if (x == 0 || pan(y, z))
      printf("Finite\n");
    else
      printf("Infinite\n");
  }
  return 0;
}
