#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
const int inf = (1LL << 29);
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    long long g = gcd(x, y);
    x /= g;
    y /= g;
    while ((g = gcd(y, z)) != 1) {
      while (!(y % g)) y /= g;
    }
    if (y == 1)
      printf("Finite\n");
    else
      printf("Infinite\n");
  }
  return 0;
}
