#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1000000007;
const double e = 2.718281828459;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long gcd1(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long pow_mod(long long a, long long b, long long c) {
  long long ans = 1;
  a = a % c;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % c;
    b = b / 2;
    a = (a * a) % c;
  }
  return ans;
}
int pow_int(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ans * a;
    b = b / 2;
    a = a * a;
  }
  return ans;
}
long long pow_llong(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ans * a;
    b = b / 2;
    a = a * a;
  }
  return ans;
}
int Scan() {
  int res = 0, flag = 0;
  char ch;
  if ((ch = getchar()) == '-') {
    flag = 1;
  } else if (ch >= '0' && ch <= '9') {
    res = ch - '0';
  }
  while ((ch = getchar()) >= '0' && ch <= '9') {
    res = res * 10 + (ch - '0');
  }
  return flag ? -res : res;
}
void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) {
    Out(a / 10);
  }
  putchar(a % 10 + '0');
}
long long jc_mod(long long a, long long b, long long mod) {
  long long ans = 1;
  b = max(b, a - b);
  for (long long i = a; i > b; i--) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}
double lg(double a) { return (log(a) / log(10.0)); }
int lowbit(int x) { return x & -x; }
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void lisan(int *x, int n) {
  int data[100010];
  for (int i = 1; i <= n; i++) data[i] = x[i];
  sort(data + 1, data + 1 + n);
  int o = unique(data + 1, data + 1 + n) - data - 1;
  for (int i = 1; i <= n; i++)
    x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;
}
long long calc(int M) { return 1; }
int sanfen(int L, int R) {
  int M, RM;
  while (L + 1 < R) {
    M = (L + R) / 2;
    RM = (M + R) / 2;
    if (calc(M) < calc(RM))
      R = RM;
    else
      L = M;
  }
  return L;
}
int CaculateWeekDay(int y, int m, int d) {
  if (m == 1 || m == 2) {
    m += 12;
    y--;
  }
  int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
  return iWeek;
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    long long p, q, b;
    scanf("%I64d", &p);
    ;
    scanf("%I64d", &q);
    ;
    scanf("%I64d", &b);
    ;
    q = q / gcd(q, p);
    while (1) {
      long long r = gcd(q, b);
      if (r == 1) break;
      while (q % r == 0) q /= r;
    }
    if (q > 1)
      printf("Infinite\n");
    else
      printf("Finite\n");
  }
  return 0;
}
