#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, c;
long long mygcd(long long x, long long y) {
  long long t;
  while (y != 0) t = y, y = x % y, x = t;
  return x;
}
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%lld%lld%lld", &a, &b, &c);
    long long g = mygcd(a, b);
    a /= g;
    b /= g;
    while (b != 1 && (c = mygcd(b, c)) != 1) b /= c;
    if (b != 1)
      puts("Infinite");
    else
      puts("Finite");
  }
  return 0;
}
