#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T> readv(vector<T> &v, int x) {
  v = vector<T>(x);
  for (int(i) = int(0); i < int(x); ++i) cin >> v[i];
}
long long gcd4(long long a, long long b) {
  long long r;
  if (b > a) {
    r = b % a;
    if (r == 0LL) return a;
    if (r == 1LL) return 1LL;
    b = r;
  }
  while (true) {
    r = a % b;
    if (r == 0LL) return b;
    if (r == 1LL) return 1LL;
    a = b;
    b = r;
  }
}
long long p, q, b;
void _input() { cin >> p >> q >> b; }
bool solve() {
  if (p == 0) return true;
  long long x = gcd4(p, q);
  p /= x;
  q /= x;
  b = gcd4(q, b);
  while (b != 1) {
    while (q % b == 0) q /= b;
    b = gcd4(q, b);
  }
  return q == 1;
}
void _solve() {
  string sol = "Inf";
  if (solve()) sol = "F";
  cout << sol << "inite\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int qq = 1;
  cin >> qq;
  int cc = 0;
  while (cc++ < qq) {
    _input();
    _solve();
  }
}
