#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (a % b != 0) {
    long long aux = a % b;
    a = b;
    b = aux;
  }
  return b;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long a, b, d;
    cin >> a >> b >> d;
    long long div = gcd(a, b);
    a /= div;
    b /= div;
    while (true) {
      div = gcd(b, d);
      if (1 == div)
        break;
      else {
        while (b % div == 0) b /= div;
        d = div;
      }
    }
    if (b == 1)
      cout << "Finite\n";
    else
      cout << "Infinite\n";
  }
  return 0;
}
