#include <bits/stdc++.h>
template <typename LhsType, typename RhsType>
auto gcd(LhsType lhs, RhsType rhs) -> decltype(lhs + rhs) {
  while (lhs > 0 && rhs > 0) {
    if (lhs > rhs)
      lhs %= rhs;
    else
      rhs %= lhs;
  }
  return lhs + rhs;
}
class Solution {
 public:
  void solve(std::istream &in, std::ostream &out) {
    long long n;
    in >> n;
    for (int i = 0; i < n; ++i) {
      long long p, q, b;
      in >> p >> q >> b;
      q /= gcd(p, q);
      auto g = gcd(q, b);
      while (g > 1) {
        q /= g;
        g = gcd(g, q);
      }
      if (q > 1)
        out << "Infinite\n";
      else
        out << "Finite\n";
    }
  }
};
void solve(std::istream &in, std::ostream &out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  using namespace std;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream &in = cin;
  ostream &out = cout;
  solve(in, out);
  return 0;
}
