#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   const int maxn = 2e5 + 5;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     long long maxl = 1e18 + 2;     for (int i = 0; i < n; i++) {       long long p, q, b;       cin >> p >> q >> b;       if (p % q == 0) {         cout <<  Finite  << endl;         continue;       }       long long g = gcd(p, q);       p /= g;       q /= g;       while (true) {         if (q == 1) {           cout <<  Finite  << endl;           break;         }         g = gcd(b, q);         if (g == 1) {           cout <<  Infinite  << endl;           break;         }         q /= g;         b = g;       }     }   }   