#include <bits/stdc++.h>
using namespace std;
inline long long read_num() {
  char c;
  while (c = getchar(), c <= ' ')
    ;
  long long res = c - '0';
  while (c = getchar(), c >= '0' && c <= '9') {
    res = res * 10 + (c - '0');
  }
  return res;
}
inline long long gcd(long long a, long long b) {
  while (b) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}
inline bool solve1(long long q, long long b) {
  long long g;
  while ((g = gcd(q, b)) != 1)
    while (q % g == 0) q /= g;
  return q == 1;
}
inline bool solve2(long long q, long long b) {
  long long g;
  while ((g = gcd(q, b)) != 1) q /= g;
  return q == 1;
}
inline bool solve3(long long q, long long b) {
  while ((b = gcd(q, b)) != 1) q /= b;
  return q == 1;
}
inline bool solve4(long long q, long long b) {
  while ((b = gcd(q, b)) != 1)
    while (q % b == 0) q /= b;
  return q == 1;
}
int main() {
  int T = read_num();
  long long p, q, b;
  while (T--) {
    p = read_num();
    q = read_num();
    b = read_num();
    q /= gcd(p, q);
    while ((b = gcd(q, b)) != 1) q /= b;
    if (q == 1)
      puts("Finite");
    else
      puts("Infinite");
  }
}
