#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;

struct Seg
{
       int fx, fy, tx, ty, number;
       Seg () {}
       Seg (int _fx, int _fy, int _tx, int _ty, int _number) :
           fx(_fx), fy(_fy), tx(_tx), ty(_ty), number(_number) {}
}      a[200050], h[200050], v[200050], hh[200050], vv[200050], doing[200050];

struct Tedge
{
       int to, flag, next;
}      edge[1000050], mem[1000050];

struct Tree1
{
       int f, down;
}      tree1[10000050];

int now, sf, nx, ny, nnx, nny, group, first[1000050], last[1000050], up[1000050], scale[1000050];
int x[1000050], y[1000050], xx[1000050], yy[1000050], father[200050], sum[4000050];
int turn[200050], belong[200050];
bool firsttime;
vector <pair <int, int> > tree[4000050];
long long result;
map <pair <int, int>, bool> f;

int Rand()
{
    return (rand() << 15) | rand();
}

void Addedge(int x, int y, int flag)
{
     edge[++now].to = y;
     edge[now].flag = flag;
     edge[now].next = first[x];
     first[x] = now;

     return;
}

void Addedges(int x, int y, int flag)
{
     mem[++sf].to = y;
     mem[sf].flag = flag;
     mem[sf].next = last[x];
     last[x] = sf;

     return;
}

int  Halfx(int ask)
{
int  low, mid, high;

     low = 0;
     high = nx + 1;
     while (low + 1 < high)
     {
           mid = (low + high) >> 1;
           if  (xx[mid] <= ask)
           {
               low = mid;
           }   else
           {
               high = mid;
           }
     }

     return low;
}

int  Halfy(int ask)
{
int  low, mid, high;

     low = 0;
     high = ny + 1;
     while (low + 1 < high)
     {
           mid = (low + high) >> 1;
           if  (yy[mid] <= ask)
           {
               low = mid;
           }   else
           {
               high = mid;
           }
     }

     return low;
}

int  Father(int current)
{
     if  (father[current] != current)
     {
         father[current] = Father(father[current]);
     }

     return father[current];
}

void Down1(int root)
{
     if  (tree1[root].down != 0)
     {
         if  (tree1[root].f == 0)
         {
             tree1[root].down = 0;
             return;
         }
         father[Father(tree1[root].f)] = Father(tree1[root].down);
         if  (tree1[root << 1].down != 0)
         {
             father[Father(tree1[root << 1].down)] = Father(tree1[root].down);
         }
         if  (tree1[(root << 1) | 1].down != 0)
         {
             father[Father(tree1[(root << 1) | 1].down)] = Father(tree1[root].down);
         }
         tree1[root << 1].down = tree1[root].down;
         tree1[(root << 1) | 1].down = tree1[root].down;
         tree1[root].down = 0;
     }

     return;
}

void Force1(int root, int nowleft, int nowright, int askleft, int askright, int news)
{
int  mid = (nowleft + nowright) >> 1;

     Down1(root);
     if  (nowright < askleft || askright < nowleft)
     {
         return;
     }
     if  (askleft <= nowleft && nowright <= askright)
     {
         tree1[root].f = news;
         return;
     }
     Force1(root << 1, nowleft, mid, askleft, askright, news);
     Force1((root << 1) | 1, mid + 1, nowright, askleft, askright, news);
     tree1[root].f = max(tree1[root << 1].f, tree1[(root << 1) | 1].f);

     return;
}

void Update1(int root, int nowleft, int nowright, int askleft, int askright, int news)
{
int  mid = (nowleft + nowright) >> 1;

     Down1(root);
     if  (nowright < askleft || askright < nowleft)
     {
         return;
     }
     if  (askleft <= nowleft && nowright <= askright)
     {
         tree1[root].down = news;
         Down1(root);
         return;
     }
     Update1(root << 1, nowleft, mid, askleft, askright, news);
     Update1((root << 1) | 1, mid + 1, nowright, askleft, askright, news);
     tree1[root].f = max(tree1[root << 1].f, tree1[(root << 1) | 1].f);

     return;
}

int  Ask1(int root, int nowleft, int nowright, int askleft, int askright)
{
int  mid = (nowleft + nowright) >> 1;

     Down1(root);
     if  (nowright < askleft || askright < nowleft)
     {
         return 0;
     }
     if  (askleft <= nowleft && nowright <= askright)
     {
         return Father(tree1[root].f);
     }

     return max(Ask1(root << 1, nowleft, mid, askleft, askright),
                Ask1((root << 1) | 1, mid + 1, nowright, askleft, askright));
}

bool Cv(Seg a, Seg b)
{
     return a.fx < b.fx ||
            a.fx == b.fx &&
            a.fy < b.fy;
}

int  X(int ask)
{
int  low, mid, high;

     low = 0;
     high = nnx + 1;
     while (low + 1 < high)
     {
           mid = (low + high) >> 1;
           if  (x[mid] <= ask)
           {
               low = mid;
           }   else
           {
               high = mid;
           }
     }

     return low;
}

int  Y(int ask)
{
int  low, mid, high;

     low = 0;
     high = nny + 1;
     while (low + 1 < high)
     {
           mid = (low + high) >> 1;
           if  (y[mid] <= ask)
           {
               low = mid;
           }   else
           {
               high = mid;
           }
     }

     return low;
}

int  Up(int current)
{
     if  (up[current] != current)
     {
         up[current] = Up(up[current]);
     }

     return up[current];
}

void Clear(int root, int nowleft, int nowright)
{
int  mid = (nowleft + nowright) >> 1;

     tree[root].clear();
     sum[root] = 0;
     if  (nowleft == nowright)
     {
         return;
     }
     Clear(root << 1, nowleft, mid);
     Clear((root << 1) | 1, mid + 1, nowright);

     return;
}

void Force(int root, int nowleft, int nowright, int askleft, int askright, int news)
{
int  mid = (nowleft + nowright) >> 1;

     if  (nowright < askleft || askright < nowleft)
     {
         return;
     }
     tree[root].push_back(make_pair(news, 1));
     if  (askleft <= nowleft && nowright <= askright)
     {
         return;
     }
     Force(root << 1, nowleft, mid, askleft, askright, news);
     Force((root << 1) | 1, mid + 1, nowright, askleft, askright, news);

     return;
}

void D1(int root, int nowleft, int nowright, int askleft, int askright, int one, int two)
{
int  mid = (nowleft + nowright) >> 1;

     if  (nowright < askleft || askright < nowleft)
     {
         return;
     }
     if  (nowleft <= one && one <= nowright ||
         nowleft <= two && two <= nowright)
     {
         sum[root]--;
     }
     if  (askleft <= nowleft && nowright <= askright)
     {
         return;
     }
     D1(root << 1, nowleft, mid, askleft, askright, one, two);
     D1((root << 1) | 1, mid + 1, nowright, askleft, askright, one, two);

     return;
}

void Update(int root, int nowleft, int nowright, int askleft, int askright)
{
int  mid = (nowleft + nowright) >> 1, sizes, next, temp, i;
map <pair <int, int>, bool>::iterator it;

     if  (nowright < askleft || askright < nowleft)
     {
         return;
     }
     if  (askleft <= nowleft && nowright <= askright)
     {
         temp = tree[root].size();
         if  (temp == 0)
         {
             return;
         }
         sizes = 0;
         result += sum[root];
         for (i = 0; i < temp; i++)
         {
             next = Up(tree[root][i].first);
             sizes += tree[root][i].second;
             result += tree[root][i].second;
             if  (firsttime)
             {
                 result--;
                 group = next;
                 firsttime = false;
                 continue;
             }
             if  (group == next)
             {
                 continue;
             }
             result--;
             if  (scale[group] < scale[next])
             {
                 swap(group, next);
             }
             scale[group] += scale[next];
             up[next] = group;
             while (true)
             {
                   it = f.lower_bound(make_pair(next, -999999999));
                   if  (it -> first.first != next)
                   {
                       break;
                   }
                   f.insert(make_pair(make_pair(group, it -> first.second), true));
                   f.erase(it);
             }
         }
         tree[root].clear();
         tree[root].push_back(make_pair(group, sizes));
         return;
     }
     Update(root << 1, nowleft, mid, askleft, askright);
     Update((root << 1) | 1, mid + 1, nowright, askleft, askright);

     return;
}

long long Solve(int total)
{
int  nh, nv, i, j, ts, temp, pointer, next, flag, l, r, a, b, p, q, ad, one, two;
long long all;
map <pair <int, int>, bool>::iterator it;

     nh = nv = nnx = nny = all = result = 0;
     for (i = 1; i <= total; i++)
     {
         x[++nnx] = doing[i].fx;
         x[++nnx] = doing[i].tx;
         y[++nny] = doing[i].fy;
         y[++nny] = doing[i].ty;
         if  (doing[i].fx != doing[i].tx)
         {
             hh[++nh] = doing[i];
         }   else
         {
             vv[++nv] = doing[i];
         }
         all += doing[i].tx - doing[i].fx +
                doing[i].ty - doing[i].fy;
     }

     for (i = 1; i <= nh; i++)
     {
         up[i] = i;
         scale[i] = 1;
     }

     sort(x + 1, x + nnx + 1);

     for (i = j = 1; i < nnx; i++)
     if  (x[i + 1] != x[j])
     {
         x[++j] = x[i + 1];
     }
     nnx = j;

     sort(y + 1, y + nny + 1);

     for (i = j = 1; i < nny; i++)
     if  (y[i + 1] != y[j])
     {
         y[++j] = y[i + 1];
     }
     nny = j;

     memset(last, 0, 4 * nnx + 4);
     sf = 0;

     for (i = 1; i <= nh; i++)
     {
         Addedges(X(hh[i].fx), i, 0);
         Addedges(X(hh[i].tx), i, 2);
     }
     for (i = 1; i <= nv; i++)
     {
         Addedges(X(vv[i].fx), i, 1);
     }

     Clear(1, 1, nny);
     f.clear();
     f.insert(make_pair(make_pair(-999999999, -999999999), true));
     f.insert(make_pair(make_pair(999999999, 999999999), true));
     for (i = 1; i <= nnx; i++)
     {
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 0)
             {
                 continue;
             }
             ad = Y(hh[next].fy);
             Force(1, 1, nny, ad, ad, next);
             f.insert(make_pair(make_pair(next, ad), true));
         }
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 1)
             {
                 continue;
             }
             firsttime = true;
             Update(1, 1, nny, Y(vv[next].fy), Y(vv[next].ty));
         }
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 2)
             {
                 continue;
             }
             one = two = 999999999;
             ad = Y(hh[next].fy);
             temp = Up(next);
             it = f.find(make_pair(temp, ad));
             it--;
             if  (it -> first.first == temp)
             {
                 one = it -> first.second;
             }
             it++;
             it++;
             if  (it -> first.first == temp)
             {
                 two = it -> first.second;
             }
             it--;
             f.erase(it);
             D1(1, 1, nny, ad, ad, one, two);
         }
     }

     return all - result;

     /*

     for (i = 1; i <= nh; i++)
     {
         scale[i] = 1;
     }

     sort(x + 1, x + nnx + 1);
     for (i = j = 1; i < nnx; i++)
     if  (x[i + 1] != x[j])
     {
         x[++j] = x[i + 1];
     }
     nnx = j;

     sort(y + 1, y + nny + 1);
     for (i = j = 1; i < nny; i++)
     if  (y[i + 1] != y[j])
     {
         y[++j] = y[i + 1];
     }
     nny = j;

     sort(vv + 1, vv + nv + 1, Cv);

     memset(last, 0, 4 * (nnx + 1));
     sf = 0;
     for (i = 1; i <= nh; i++)
     {
         Addedges(X(hh[i].fx), i, 0);
         Addedges(X(hh[i].tx), i, 2);
     }
     for (i = 1; i <= nv; i++)
     {
         Addedges(X(vv[i].fx), i, 1);
     }

     Clear(1, 1, nny);
     for (i = 1; i <= nnx; i++)
     {
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 0)
             {
                 continue;
             }
             Force(1, 1, nny, Y(hh[next].fy), Y(hh[next].fy), next);
         }
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 1)
             {
                 continue;
             }
             Update(1, 1, nny, Y(vv[next].fy), Y(vv[next].ty), next + nh);
         }
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 2)
             {
                 continue;
             }
             scale[Up(next)]--;
         }
     }

     turn[ts = 1] = 1;
     for (i = 2; i <= nv; i++)
     if  (vv[i].fx != vv[i - 1].fx)
     {
         turn[++ts] = i;
     }

     memset(last, 0, 4 * (nnx + 1));
     sf = 0;

     for (i = 1; i <= nh; i++)
     {
         Addedges(X(hh[i].fx), i, 0);
         Addedges(X(hh[i].tx), i, 2);
     }

     temp = X(vv[1].fx);
     for (i = 1; i <= temp; i++)
     {
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 0)
             {
                 continue;
             }
             Update(1, 1, nny, Y(hh[next].fy), Y(hh[next].fy), 1);
         }
         for (pointer = last[i]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 2)
             {
                 continue;
             }
             Update(1, 1, nny, Y(hh[next].fy), Y(hh[next].fy), -1);
         }
     }

     turn[ts + 1] = nv + 1;
     sum = 0;

     for (i = 2; i <= ts; i++)
     {
         l = X(vv[turn[i - 1]].fx);
         r = X(vv[turn[i]].fx);
         //*************************************
         for (j = l + 1; j < r; j++)
         {
             for (pointer = last[j]; pointer; pointer = mem[pointer].next)
             {
                 next = mem[pointer].to;
                 flag = mem[pointer].flag;
                 if  (flag != 2)
                 {
                     continue;
                 }
                 Update(1, 1, nny, Y(hh[next].fy), Y(hh[next].fy), -1);
             }
         }
         //solve
         for (a = turn[i - 1], b = turn[i]; a < turn[i] && b < turn[i + 1];)
         {
             p = max(vv[a].fy, vv[b].fy);
             q = min(vv[a].ty, vv[b].ty);
             if  (p < q)
             {
                 sum += max(Ask(1, 1, nny, Y(p), Y(q)) - 1, 0);
             }
             if  (vv[a].ty < vv[b].ty)
             {
                 a++;
             }   else
             {
                 b++;
             }
         }
         //*************************************
         for (pointer = last[r]; pointer; pointer = mem[pointer].next)
         {
             next = mem[pointer].to;
             flag = mem[pointer].flag;
             if  (flag != 2)
             {
                 continue;
             }
             Update(1, 1, nny, Y(hh[next].fy), Y(hh[next].fy), -1);
         }
         for (j = l + 1; j <= r; j++)
         {
             for (pointer = last[j]; pointer; pointer = mem[pointer].next)
             {
                 next = mem[pointer].to;
                 flag = mem[pointer].flag;
                 if  (flag != 0)
                 {
                     continue;
                 }
                 Update(1, 1, nny, Y(hh[next].fy), Y(hh[next].fy), 1);
             }
         }
     }

     all = 0;

     for (i = 1; i <= total; i++)
     {
         all += doing[i].tx - doing[i].fx +
                doing[i].ty - doing[i].fy;
     }

     return all - sum;

     return all - result;

     */
}

int main()
{
int nh, nv, n, i, j, fx, fy, tx, ty, total, pointer, next, flag, temp;
long long answer;

//    freopen("e.in", "r", stdin);
//    freopen("e.out", "w", stdout);

    srand((unsigned) time (0));

    nx = ny = nh = nv = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        scanf("%d%d%d%d", &fx, &fy, &tx, &ty);
        xx[++nx] = fx;
        xx[++nx] = tx;
        yy[++ny] = fy;
        yy[++ny] = ty;
        a[i] = Seg(fx, fy, tx, ty, i);
        if  (fx != tx)
        {
            h[++nh] = Seg(fx, fy, tx, ty, i);
        }   else
        {
            v[++nv] = Seg(fx, fy, tx, ty, i);
        }
    }

    sort(xx + 1, xx + nx + 1);
    for (i = j = 1; i < nx; i++)
    if  (xx[i + 1] != xx[j])
    {
        xx[++j] = xx[i + 1];
    }
    nx = j;

    sort(yy + 1, yy + ny + 1);
    for (i = j = 1; i < ny; i++)
    if  (yy[i + 1] != yy[j])
    {
        yy[++j] = yy[i + 1];
    }
    ny = j;

    memset(first, 0, sizeof(first));
    now = 0;
    for (i = 1; i <= nh; i++)
    {
        Addedge(Halfx(h[i].fx), h[i].number, 0);
        Addedge(Halfx(h[i].tx), h[i].number, 2);
    }
    for (i = 1; i <= nv; i++)
    {
        Addedge(Halfx(v[i].fx), v[i].number, 1);
    }

    for (i = 1; i <= n; i++)
    {
        father[i] = i;
    }
    memset(tree1, 0, sizeof(tree1));
    for (i = 1; i <= nx; i++)
    {
        for (pointer = first[i]; pointer; pointer = edge[pointer].next)
        {
            next = edge[pointer].to;
            flag = edge[pointer].flag;
            if  (flag != 0)
            {
                continue;
            }
            temp = Halfy(a[next].fy);
            Force1(1, 1, ny, temp, temp, next);
        }

        for (pointer = first[i]; pointer; pointer = edge[pointer].next)
        {
            next = edge[pointer].to;
            flag = edge[pointer].flag;
            if  (flag != 1)
            {
                continue;
            }
            Update1(1, 1, ny, Halfy(a[next].fy), Halfy(a[next].ty), next);
        }

        for (pointer = first[i]; pointer; pointer = edge[pointer].next)
        {
            next = edge[pointer].to;
            flag = edge[pointer].flag;
            if  (flag != 2)
            {
                continue;
            }
            temp = Halfy(a[next].fy);
            belong[next] = Ask1(1, 1, ny, temp, temp);
            Force1(1, 1, ny, temp, temp, 0);
        }
    }
    for (i = 1; i <= nv; i++)
    {
        belong[v[i].number] = Father(v[i].number);
    }
    for (i = 1; i <= n; i++)
    {
        belong[i] = Father(belong[i]);
    }

    memset(first, 0, sizeof(first));
    now = 0;
    for (i = 1; i <= n; i++)
    {
        Addedge(belong[i], i, 0);
    }
    answer = 0;
    for (i = 1; i <= n; i++)
    {
        total = 0;
        for (pointer = first[i]; pointer; pointer = edge[pointer].next)
        {
            next = edge[pointer].to;
            doing[++total] = a[next];
        }
        if  (total == 0)
        {
            continue;
        }
        answer = max(answer, Solve(total));
    }

    printf("%I64d\n", answer);

    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll a[N];
void solve()
{
    ll p,q,b; scanf("%lld%lld%lld",&p,&q,&b);
    p=p%q;
    int tmp_gcd=__gcd(p,q);
    p/=tmp_gcd;
    q/=tmp_gcd;
    if(!p||q==1) {
        puts("Finite");
        return;
    }
//    cout<<p<<' '<<q<<endl;
    ll tmp;
    while(q!=1){
        tmp=__gcd(q,b);
        if(tmp==1) break;
        q/=tmp;
    }
    if(q==1) puts("Finite");
    else puts("Infinite");
}
signed main(){
    int t; scanf("%lld",&t);
    while(t--) solve();
//#ifndef ONLINE_JUDGE
//    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
//#endif
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(gcd(p, q) != 1)
    {
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    }

        ll t = gcd(q, r);
        q /= t;

    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    while(q % u == 0 && u != 1)
        q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;

        ll t = gcd(p, q);
        p /= t;
        q /= t;

    //cout << r << ' ' << q << '\n';

    if(max(r, q) % min(r, q) != 0) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 31)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    while(u != 1)
    {
    	u = gcd(r, q);
    	q /= u;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;

    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;

    while(u != 1)
    {
    	u = gcd(r, u);
    	q /= u;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 32)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;

    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    while(u != 1)
    {
    	u = gcd(q, u);
    	q /= u;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 30)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    u = gcd(r, q);
    q /= u;
    u = gcd(r, q);
    q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(gcd(p, q) != 1)
    {
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    }

    while(gcd(q, r) != 1)
    {
        ll t = gcd(q, r);
        q /= t;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;

    ll t = __gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = __gcd(r, q);
    q /= u;
    while(u != 1)
    {
    	u = __gcd(q, u);
    	q /= u;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 30)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    u = gcd(r, q);
    q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

void scann(ll &x){
    x=0;
    int ch=_getchar_nolock();
    while(!isdigit(ch)) ch=_getchar_nolock();

    while(isdigit(ch)){
        x=(x<<1) + (x<<3) + ch -'0';
        ch=_getchar_nolock();
    }
}

void printn1()
{
    _putchar_nolock('I');
    _putchar_nolock('n');
    _putchar_nolock('f');
    _putchar_nolock('i');
    _putchar_nolock('n');
    _putchar_nolock('i');
    _putchar_nolock('t');
    _putchar_nolock('e');
    _putchar_nolock('\n');
}

void printn2()
{
    _putchar_nolock('F');
    _putchar_nolock('i');
    _putchar_nolock('n');
    _putchar_nolock('i');
    _putchar_nolock('t');
    _putchar_nolock('e');
    _putchar_nolock('\n');
}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
   	  scann(p);
   	  scann(q);
   	  scann(r);

    ll t = __gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = __gcd(r, q);
    q /= u;
    while(u != 1)
    {
    	u = __gcd(q, u);
    	q /= u;
    }
    if(q != 1) printn1();
        else printn2();
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 30)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    while(q % u == 0)
        {q /= u;
        u = gcd(q, r);
        }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    while(q % u != 1)
        q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    ll t, p, q, r;8
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(gcd(p, q) != 1)
    {
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    }

    while(gcd(q, r) != 1)
    {
        ll t = gcd(q, r);
        q /= t;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
        while(r < q) r *= r;
    //cout << r << ' ' << q << '\n';
    while(gcd(r, q) != 1)
        q /= gcd(r, q);
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 31)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    u = gcd(r, q);
    q /= u;
    u = gcd(r, q);
    q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(r * r <= (1ll << 62))
    {
    		if(r > (1ll << 31)) break;
			r *= r;
    }
    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;

        ll t = gcd(p, q);
        p /= t;
        q /= t;

    //cout << r << ' ' << q << '\n';
    while(gcd(r, q) != 1)
        q /= gcd(r, q);
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(gcd(p, q) != 1)
    {
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    }

    while(gcd(q, r) != 1)
    {
        ll t = gcd(q, r);
        q /= t;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;8
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
    while(gcd(p, q) != 1)
    {
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    }

    while(gcd(q, r) != 1)
    {
        ll t = gcd(q, r);
        q /= t;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;

    ll t = gcd(p, q);
    p /= t;
    q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    q /= u;
    while(u != 1)
    {
    	u = gcd(r, u);
    	q /= u;
    }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    while(q % u == 0 && u != 1)
        q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    while(q % u == 0 && u != 1)
        q /= u;
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll;

ll gcd(ll a, ll b)
{
      	while (b)
      {
       	  a %= b;
         	swap (a, b);
      	}
      	return a;

}

int main() {
    ll t, p, q, r;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
    cin >> p >> q >> r;
        ll t = gcd(p, q);
        p /= t;
        q /= t;
    //cout << r << ' ' << q << '\n';
    ll u = gcd(r, q);
    while(q % u == 0 && u != 1)
        {q /= u;
        u = gcd(q, r);
        }
    if(q != 1) cout << "Infinite" << '\n';
        else cout << "Finite" << '\n';
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;
static_assert(sizeof(long long) >= 8);
map<tuple<long long, long long, long long>, int> mem;
bool solve(long long p, long long q, long long b) {
    q /= __gcd(p, q);
    while (q != 1) {
        long long div = __gcd(b, q);
        if (div == 1)
            return false;
        do
            q /= div;
        while (q % div == 0);
    }
    return true;
}
bool mem_solve(long long p, long long q, long long b) {
    int &ref = mem[make_tuple(p, q, b)];
    if (!ref)
        ref = solve(p, q, b) + 1;
    return ref - 1;
}
int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        long long p, q, b;
        scanf("%lld %lld %lld", &p, &q, &b);
        puts(mem_solve(p, q, b) ? "Finite" : "Infinite");
    }
}


#include <cstdio>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;
static_assert(sizeof(long long) >= 8);
map<tuple<long long, long long, long long>, int> mem;
bool solve(long long p, long long q, long long b) {
    q /= __gcd(p, q);
    while (q != 1) {
        long long div = __gcd(b, q);
        if (div == 1)
            return false;
        q /= div;
    }
    return true;
}
bool mem_solve(long long p, long long q, long long b) {
    int &ref = mem[make_tuple(p, q, b)];
    if (!ref)
        ref = solve(p, q, b) + 1;
    return ref - 1;
}
int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        long long p, q, b;
        scanf("%lld %lld %lld", &p, &q, &b);
        puts(mem_solve(p, q, b) ? "Finite" : "Infinite");
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;
static_assert(sizeof(long long) >= 8);
bool solve(long long p, long long q, long long b) {
    q /= __gcd(p, q);
    while (q != 1) {
        long long div = __gcd(b, q);
        if (div == 1)
            return false;
        q /= div;
    }
    return true;
}
int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        long long p, q, b;
        scanf("%lld %lld %lld", &p, &q, &b);
        puts(solve(p, q, b) ? "Finite" : "Infinite");
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;
static_assert(sizeof(long long) >= 8);
bool solve(long long p, long long q, long long b) {
    q /= __gcd(p, q);
    for (int i = 0; i < 70; i++)
        q /= __gcd(b, q);
    return q == 1;
}
int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        long long p, q, b;
        scanf("%lld %lld %lld", &p, &q, &b);
        puts(solve(p, q, b) ? "Finite" : "Infinite");
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;
bool solve(long p, long q, long b) {
    q /= __gcd(p, q);
    for (int i = 0; i < 70; i++)
        q /= __gcd(b, q);
    return q == 1;
}
int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        long p, q, b;
        scanf("%ld %ld %ld", &p, &q, &b);
        puts(solve(p, q, b) ? "Finite" : "Infinite");
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;
bool solve(long p, long q, long b) {
    q /= __gcd(p, q);
    for (int i = 0; i < 40; i++)
        q /= __gcd(b, q);
    return q == 1;
}
int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        long p, q, b;
        scanf("%ld %ld %ld", &p, &q, &b);
        puts(solve(p, q, b) ? "Finite" : "Infinite");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    ll t,p,b,q;
    scanf("%I64d",&t);
    while(t--)
    {
        scanf("%I64d %I64d %I64d",&p,&q,&b);
        ll ans=gcd(p,q),k=q/ans,opt=gcd(k,b),d=b/opt;
        k/=opt;
        if(k%d==0||d%k==0)
            printf("Finite\n");
        else
            printf("Infinite\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t,p,b,q;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&p,&q,&b);
        int ans=gcd(p,q),k=q/ans,opt=gcd(k,b),d=b/opt;
        k/=opt;
        if(b%k==0||d%k==0)
            printf("Finite\n");
        else
            printf("Infinite\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t,p,b,q;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&p,&q,&b);
        int ans=gcd(p,q),opt=gcd(q/ans,b);
        if(opt!=1||q/ans==1)
            printf("Finite\n");
        else
            printf("Infinite\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{

    ll t,p,b,q;
    scanf("%I64d",&t);
    while(t--)
    {
        scanf("%I64d %I64d %I64d",&p,&q,&b);
        ll ans=gcd(p,q);
        q/=ans;
        ll k=b;
        while(q!=1)
        {
            k=gcd(q,k);
            q/=k;
            if(k==1)
                break;
        }
        if(q==1)
            printf("Finite\n");
        else
            printf("Infinite\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t,p,b,q;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&p,&q,&b);
        int ans=gcd(p,q),k=q/ans,opt=gcd(k,b),d=b/opt;
        k/=opt;
        if(k%d==0||d%k==0)
            printf("Finite\n");
        else
            printf("Infinite\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t,p,b,q;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&p,&q,&b);
        int ans=gcd(p,q),opt=gcd(q/ans,b);
        if(opt!=1||q/ans==1)
            printf("Finite\n");
        else
            printf("Infinite");
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf = 1e18;
const int N = 2e5 + 5;

int n , a , m  , p;

void solve(int id) {
	cin >> n >> m >> p;
	int gc = __gcd( n , m);

	int divi = m / gc;

	map<int,int> mp , mm;

	for(int i = 2 ; i*i<=divi ; i++) {
			while(divi % i == 0) {
				mp[i] ++;
				divi /= i;
			}
	}
	if(divi > 1)	mp[divi] = 1;

	for(int i = 2 ; i*i<=p ; i++){
			while(p % i == 0) {
				mm[i]++;
				p /= i;
			}
	}
	if(p > 1)	mm[p] = 1;

	for(auto x:mm) {
			if(mp.find(x.ff) != mp.end()){
					mp[x.ff] = 0;
			}
	}

	bool pass = 1;
	for(auto x:mp) {
			if(x.ss)	pass = 0;
	}

	if(pass)	cout << "Finite" << endl;
	else		cout << "Infinite" << endl;
}

int32_t main(){
	FAST;
	int t=1;
	cin>>t;

	for(int i = 1 ; i<=t ; i++)
		solve(i);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf = 1e18;
const int N = 2e5 + 5;

int n , a , m  , p;

void solve(int id) {
	cin >> n >> m >> p;
	int gc = __gcd( n , m);

	int divi = m / gc;

	map<int,int> mp , mm;

	for(int i = 2 ; i*i<=divi ; i++) {
			while(divi % i == 0) {
				mp[i] ++;
				divi /= i;
			}
	}
	if(divi > 1)	mp[divi] = 1;

	for(int i = 2 ; i*i<=p ; i++){
			while(p % i == 0) {
				mm[i]++;
				p /= i;
			}
	}
	if(p > 1)	mm[p] = 1;

	for(auto x:mm) {
			if(mp.find(x.ff) != mp.end()){
					if(mp[x.ff] % mm[x.ff] == 0)	mp[x.ff] = 0;
			}
	}

	bool pass = 1;
	for(auto x:mp) {
			if(x.ss)	pass = 0;
	}

	if(pass)	cout << "Finite" << endl;
	else		cout << "Infinite" << endl;
}

int32_t main(){
	FAST;
	int t=1;
	cin>>t;

	for(int i = 1 ; i<=t ; i++)
		solve(i);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf = 1e18;
const int N = 2e5 + 5;

int n , a , m  , p;

void solve(int id) {
	cin >> n >> m >> p;
	int gc = __gcd( n , m);

	int divi = m / gc;

	if(divi == 1 || divi%p == 0 || p%divi == 0) {
			cout << "Finite" << endl;
			return;
	}
	while(true) {
		p = __gcd( p , divi);
		if(p == 1){
			cout << "Infinite" << endl;
			return;
		}
		divi /= p;
		if(divi == 1){
			cout << "Finite" << endl;
			return;
		}
	}
}

int32_t main(){
	FAST;
	int t=1;
	cin>>t;

	for(int i = 1 ; i<=t ; i++)
		solve(i);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf = 1e18;
const int N = 2e5 + 5;

int n , a , m  , p;

void solve(int id) {
	cin >> n >> m >> p;
	int gc = __gcd( n , m);

	int divi = m / gc;

	if(divi == 1 && divi%p == 0 && p%divi == 0) {
			cout << "Finite" << endl;
			return;
	}
	while(true) {
		p = __gcd( p , divi);
		if(p == 1){
			cout << "Infinite" << endl;
			return;
		}
		divi /= p;
		if(divi == 1){
			cout << "Finite" << endl;
			return;
		}
	}
}

int32_t main(){
	FAST;
	int t=1;
	cin>>t;

	for(int i = 1 ; i<=t ; i++)
		solve(i);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf = 1e18;
const int N = 2e5 + 5;

int n , a , m  , p;

void solve(int id) {
	cin >> n >> m >> p;
	int gc = __gcd( n , m);

	int divi = m / gc;

	if(divi == 1 && divi%p == 0 && p%divi == 0) {
			cout << "Finite" << endl;
			return;
	}
	map<int,int> mp , mm;

	for(int i = 2 ; i*i<=divi ; i++) {
			while(divi % i == 0) {
				mp[i] ++;
				divi /= i;
			}
	}
	if(divi > 1)	mp[divi] = 1;

	for(int i = 2 ; i*i<=p ; i++){
			while(p % i == 0) {
				mm[i]++;
				p /= i;
			}
	}
	if(p > 1)	mm[p] = 1;

	for(auto x:mm) {
			if(mp.find(x.ff) != mp.end()){
					mp[x.ff] = 0;
			}
	}

	bool pass = 1;
	for(auto x:mp) {
			if(x.ss)	pass = 0;
	}

	if(pass)	cout << "Finite" << endl;
	else		cout << "Infinite" << endl;
}

int32_t main(){
	FAST;
	int t=1;
	cin>>t;

	for(int i = 1 ; i<=t ; i++)
		solve(i);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf = 1e18;
const int N = 2e5 + 5;

int n , a , m  , p;

void solve(int id) {
	cin >> n >> m >> p;
	int gc = __gcd( n , m);

	int divi = m / gc;

	if(divi == 1) {
			cout << "Finite" << endl;
			return;
	}
	while(true) {
		p = __gcd( p , divi);
		if(p == 1){
			cout << "Infinite" << endl;
			return;
		}
		divi /= p;
		if(divi == 1){
			cout << "Finite" << endl;
			return;
		}
	}
}

int32_t main(){
	FAST;
	int t=1;
	cin>>t;

	for(int i = 1 ; i<=t ; i++)
		solve(i);

	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(15);

    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = (ull)__gcd(p,q);
        p /= gc;
        q /= gc;

        while (b%q != 0 && q%b != 0 && a!=p){
            a = p;
            p/=q;
            p+=a%q;
            gc = (ull)__gcd(p,q);
            p /= gc;
            q /= gc;
        }

        if (b%q == 0 || q%b == 0){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(15);

    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = (ull)__gcd(p,q);
        p /= gc;
        q /= gc;
        gc = (ull)__gcd(q,b);
        b/=gc;
        ull fb = b;

        while (b%q != 0 && b <= (ull)pow(10,18) && b!=1){
            if (b > (ull)pow(10,9)){
                b*=fb;
            }else{
                b*=b;
            }
            //cout << b << endl;
        }
        if (b%q==0 || b == 1){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	while (n--) {
		long long p, q, b;
		cin >> p >> q >> b;
		long long g = gcd(p, q);
		q /= g;
		b = gcd(q, b);
		while (b != 1) {
			while (q % b == 0) q /= b;
			b = gcd(q, b);
		}
		if (q == 1)
			cout << "Finite\n";
		else
			cout << "Infinite\n";
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(15);

    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = (ull)__gcd(p,q);
        p /= gc;
        q /= gc;
        gc = (ull)__gcd(q,b);
        b/=gc;
        ull fb = b;

        while (b%q != 0 && b <= (ull)pow(10,18) && b!=1){
            if (b > (ull)pow(10,9)){
                b*=fb;
            }else{
                b*=b;
            }
            cout << b << endl;
        }
        if (b%q==0 || b == 1){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(15);

    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = __gcd(p,q);
        p /= gc;
        q /= gc;

        while (b%q != 0 && q%b != 0 && a!=p){
            a = p;
            p/=q;
            p+=a%q;
            gc = __gcd(p,q);
            p /= gc;
            q /= gc;
        }
        a = p;
        p/=q;
        p+=a%q;
        gc = __gcd(p,q);
        p /= gc;
        q /= gc;

        if (b%q == 0 || q%b == 0){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef unsigned long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = (ull)__gcd(p,q);
        q /= gc;
        b = (ull)__gcd(q,b);
        q/=b;

        while(b!=1){
            while(q%b == 0) q/=b;
            b = (ull)__gcd(q,b);
        }

        if (q==1){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(15);

    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = __gcd(p,q);
        p /= gc;
        q /= gc;

        while (b%q != 0 && q%b != 0 && a!=p){
            a = p;
            p/=q;
            p+=a%q;
            gc = __gcd(p,q);
            p /= gc;
            q /= gc;
        }

        if (b%q == 0 || q%b == 0){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long long ull;
#define pii pair<int,int>
#define pll pair<ull,ull>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 1000100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(15);

    int n;
    cin >> n;
    fo(i,0,n){
        ull a,p,q,b;
        cin >> p >> q >> b;
        ull gc = (ull)__gcd(p,q);
        p /= gc;
        q /= gc;
        gc = (ull)__gcd(q,b);
        b/=gc;
        q/=gc;
        ull fb = b;

        while (b%q != 0 && b <= (ull)pow(10,18) && b!=1){
            b*=fb;
        }
        if (b%q==0 || b == 1){
            cout << "Finite" << endl;
        }else{
            cout << "Infinite" << endl;
        }
    }

    return 0;
}


#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cout << #x << " : " << x << endl
//#define PI 3.141592653589

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;

/*
const ll MAX_MEM = 2e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

void solve()
{
    int p, q;
    cin >> p >> q;
    int b;
    cin >> b;
    int gpq = gcd(p, q);
    p /= gpq, q /= gpq;
    if (b % q == 0 || q % b == 0)
        cout << "Finite\n";
    else
        cout << "Infinite\n";
}

signed main()
{
    Start();
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cout << #x << " : " << x << endl
//#define PI 3.141592653589

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;

/*
const ll MAX_MEM = 2e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

void solve()
{
    int p, q;
    cin >> p >> q;
    int b;
    cin >> b;
    int gpq = gcd(p, q);
    p /= gpq, q /= gpq;
    if (gcd(b, q) == q || gcd(b, q) == b)
        cout << "Finite\n";
    else
        cout << "Infinite\n";
}

signed main()
{
    Start();
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cout << #x << " : " << x << endl
//#define PI 3.141592653589

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;

/*
const ll MAX_MEM = 2e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

void solve()
{
    int p, q;
    cin >> p >> q;
    int b;
    cin >> b;
    int gpq = __gcd(p, q);
    p /= gpq, q /= gpq;
    while (q != 1)
    {
        int g = __gcd(q, b);
        q /= g;
        if (g == 1)
            break;
    }
    if (q != 1)
        cout << "Infinite\n";
    else
        cout << "Finite\n";
}

signed main()
{
    Start();
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cout << #x << " : " << x << endl
//#define PI 3.141592653589

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;

/*
const ll MAX_MEM = 2e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

void solve()
{
    int p, q;
    cin >> p >> q;
    int b;
    cin >> b;
    int gpq = __gcd(p, q);
    p /= gpq, q /= gpq;
    while (q != 1)
    {
        int g = __gcd(q, b);
        if (g == 1)
            break;
        while (q % g == 0)
            q /= g;
    }
    if (q != 1)
        cout << "Infinite\n";
    else
        cout << "Finite\n";
}

signed main()
{
    Start();
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cout << #x << " : " << x << endl
//#define PI 3.141592653589

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;

/*
const ll MAX_MEM = 2e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

void solve()
{
    int p, q;
    cin >> p >> q;
    int b;
    cin >> b;
    int gpq = gcd(p, q);
    p /= gpq, q /= gpq;
    if (b % q == 0)
    {
        cout << "Finite\n";
        return;
    }
    if (q % b != 0)
    {
        cout << "Infinite\n";
        return;
    }
    while (q % b == 0)
        q /= b;
    if (b % q != 0)
        cout << "Infinite\n";
    else
        cout << "Finite\n";
}

signed main()
{
    Start();
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }

    return a;
}

void solve()
{
    int p, q, b;
    cin >> p >> q >> b;
    q /= gcd(p, q);
    while (q != 1)
    {
        int g = gcd(q, b);
        if (g == 1)
        {
            cout << "Infinite" << endl;
            return;
        }
        while (q % g == 0)
            q /= g;
    }
    cout << "Finite" << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    for (cin >> n; n--;)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }

    return a;
}

void solve()
{
    int p, q, b;
    cin >> p >> q >> b;
    q /= gcd(p, q);
    while (q != 1)
    {
        int g = gcd(q, b);
        if (g == 1)
        {
            cout << "Infinite" << endl;
            return;
        }
        while (q % g == 0)
            q /= g;
    }
    cout << "Finite" << endl;
}

signed main()
{
    int n;
    for (cin >> n; n--;)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }

    return a;
}

void solve()
{
    int p, q, b;
    scanf("%lld %lld %lld", &p, &q, &b);
    q /= gcd(p, q);
    while (q != 1)
    {
        int g = gcd(q, b);
        if (g == 1)
        {
            printf("Infinite\n");
            return;
        }
        while (q % g == 0)
            q /= g;
    }
    printf("Finite\n");
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    for (scanf("%lld", &n); n--;)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }

    return a;
}

void solve()
{
    int p, q, b;
    cin >> p >> q >> b;
    q /= gcd(p, q);
    while (q != 1)
    {
        int g = gcd(q, b);
        if (g == 1)
        {
            cout << "Infinite\n";
            return;
        }
        while (q % g == 0)
            q /= g;
    }
    cout << "Finite\n";
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    for (scanf("%lld", &n); n--;)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }

    return a;
}

void solve()
{
    int p, q, b;
    cin >> p >> q >> b;
    q /= gcd(p, q);
    while (q != 1)
    {
        int g = gcd(q, b);
        if (g == 1)
        {
            cout << "Infinite\n";
            return;
        }
        while (q % g == 0)
            q /= g;
    }
    cout << "Finite\n";
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    for (cin >> n; n--;)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();

int main(){
    //ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll long long
ll a;
inline ll readll()
{
    ll ans=0;
    char c;
    while((c=getchar())!=EOF&&!(c>='0'&&c<='9'));
    do{
        ans=ans*10-'0'+c;
        c=getchar();
    }while(c>='0'&&c<='9');
    return ans;
}
inline ll gcd(ll a,ll b)
{
    if(a==0)    return b;
    if(b==0)    return a;
    return gcd(b%a,a);
}
    char* y="Finite",*no="Infinite";
void smain(){
    long long p,q,b,g;
    int n;
    n=readll();
    while(n--)
    {
        p=readll();
        q=readll();
        b=readll();
        p%=q;
        if(p==0)
        {
            printf("%s\n",y);
            continue;
        }
        g=gcd(p,q);
        q/=g;
        while((g=gcd(q,b))!=1)
            q/=g;
        if(b%q==0)    printf("%s\n",y);
        else printf("%s\n",no);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();
int main(){
    ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll long long
ll a;
void smain(){
    long long p,q,b;
    int n;
    cin>>n;
    string y="Finite",no="Infinite";
    while(n--)
    {
        cin>>p>>q>>b;
        if(p==0)
        {
            cout<<y<<endl;
            continue;
        }
        long long g=__gcd(p,q);
        q/=g;
        for(int i=0;i<64;++i)
        {
            q/=__gcd(q,b);
        }
        if(b%q==0)    cout<<y<<endl;
        else cout<<no<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();
int main(){
    ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll __int128
ll a;
void smain(){
    long long p,q,b;
    int n;
    cin>>n;
    string y="Finite",no="Infinite";
    while(n--)
    {
        cin>>p>>q>>b;
        if(p==0)
        {
            cout<<y<<endl;
            continue;
        }
        long long g=__gcd(p,q);
        q/=g;
        ll qq=q,bb=b;
        while(bb<qq)
        {
            bb=bb*b;
        }
        if(bb%qq==0)    cout<<y<<endl;
        else cout<<no<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();
int main(){
    ios::sync_with_stdio(false);
    smain();
    return 0;
}
//#define ll __int128
ll a;
void smain(){
    long long p,q,b;
    int n;
    cin>>n;
    string y="Finite",no="Infinite";
    while(n--)
    {
        cin>>p>>q>>b;
        if(p==0)
        {
            cout<<y<<endl;
            continue;
        }
        long long g=__gcd(p,q);
        q/=g;
        __int128 qq=q,bb=b;
        while(bb<qq)
        {
            bb=bb*b;
        }
        if(bb%qq==0)    cout<<y<<endl;
        else cout<<no<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();

int main(){
    //ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll long long
ll a;
inline ll readll()
{
    ll ans=0;
    char c;
    while((c=getchar())!=EOF&&!(c>='0'&&c<='9'));
    do{
        ans=ans*10-'0'+c;
        c=getchar();
    }while(c>='0'&&c<='9');
    return ans;
}
ll gcd(ll a,ll b)
{
    if(a==0)    return b;
    if(b==0)    return a;
    return gcd(b%a,a);
}
    char* y="Finite",*no="Infinite";
void smain(){
    long long p,q,b,g;
    int n;
    n=readll();
    while(n--)
    {
        p=readll();
        q=readll();
        b=readll();
        p%=q;
        if(p==0)
        {
            printf("%s\n",y);
            continue;
        }
        g=gcd(p,q);
        q/=g;
        while((g=gcd(q,b))!=1)
            q/=g;
        if(b%q==0)    printf("%s\n",y);
        else printf("%s\n",no);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();

int main(){
    //ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll long long
ll a;
inline ll readll()
{
    ll ans=0;
    char c;
    while((c=getchar())!=EOF&&!(c>='0'&&c<='9'));
    do{
        ans=ans*10-'0'+c;
        c=getchar();
    }while(c>='0'&&c<='9');
    return ans;
}
inline ll gcd(ll a,ll b)
{
    if(a==0)    return b;
    if(b==0)    return a;
    return gcd(b%a,a);
}
    char* y="Finite",*no="Infinite";
bool solve(ll a,ll b)
{

}
void smain(){
    long long p,q,b,g;
    int n;
    n=readll();
    while(n--)
    {
        p=readll();
        q=readll();
        b=readll();
        p%=q;
        if(p==0)
        {
            printf("%s\n",y);
            continue;
        }
        g=gcd(p,q);
        q/=g;
        while((g=gcd(g,q)!=1)
            q/=g;
        if(q==1)    printf("%s\n",y);
        else printf("%s\n",no);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();
int main(){
    ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll long long
ll a;
ll gcd(ll a,ll b)
{
    if(a==0)    return b;
    if(b==0)    return a;
    return gcd(b%a,a);
}
void smain(){
    long long p,q,b;
    int n;
    cin>>n;
    string y="Finite",no="Infinite";
    while(n--)
    {
        cin>>p>>q>>b;
        if(p==0)
        {
            cout<<y<<endl;
            continue;
        }
        long long g=gcd(p,q);
        q/=g;
        while((g=gcd(q,b))!=1)
            q/=g;
        if(b%q==0)    cout<<y<<endl;
        else cout<<no<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();

int main(){
    //ios::sync_with_stdio(false);
    smain();
    return 0;
}
#define ll long long
ll a;
inline ll readll()
{
    ll ans=0;
    char c;
    while((c=getchar())!=EOF&&!(c>='0'&&c<='9'));
    do{
        ans=ans*10-'0'+c;
        c=getchar();
    }while(c>='0'&&c<='9');
    return ans;
}
inline ll gcd(ll a,ll b)
{
    if(a==0)    return b;
    if(b==0)    return a;
    return gcd(b%a,a);
}
    char* y="Finite",*no="Infinite";
bool solve(ll a,ll b)
{

}
void smain(){
    long long p,q,b,g;
    int n;
    n=readll();
    while(n--)
    {
        p=readll();
        q=readll();
        b=readll();
        p%=q;
        if(p==0)
        {
            printf("%s\n",y);
            continue;
        }
        g=gcd(p,q);
        q/=g;
        g=gcd(q,b);
        while((g=gcd(q,g))!=1)
            q/=g;
        if(q==1)    printf("%s\n",y);
        else printf("%s\n",no);
    }
}


#include <iostream>
using namespace std;
long long int Nod(long long int a, long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
     long long int a,b,c,d,e;
     int n;
    cin>>n;
    while(n--){
    cin>>a>>b>>c;
    if (a!=0){
    d=Nod(a,b);
    b/=d;
    c=Nod(b,c);
    while(c!=1){
        while (b%c==0)b/=c;
        c=Nod(b,c);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
    else cout<<"Finite\n";
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(unsigned long long int a, unsigned long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    unsigned long long int a,b,c,d,e,n;
    cin>>n;
    for (unsigned long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    d=Nod(a,b);
    b/=d;
    e=Nod(b,c);
    while(e!=1){
        b/=e;
        e=Nod(b,e);
    }
    if (b!=1)cout<<"Infinite"<<endl;
    else cout<<"Finite"<<endl;
    }
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(long long int a, long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long int a,b,c,d,e,n;
    cin>>n;
    for ( long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    if (a!=0){
    d=Nod(a,b);
    b/=d;
    c=Nod(b,c);
    while(c!=1){
        while (b%c==0)b/=c;
        c=Nod(b,c);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
    else cout<<"Finite\n";
    }
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(long long int a, long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long int a,b,c,d,e,n;
    cin>>n;
    for ( long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    d=Nod(a,b);
    b/=d;
    e=Nod(b,c);
    while(e!=1){
        while (b%e==0)b/=e;
        e=Nod(b,e);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
}


#include <iostream>
using namespace std;
long long int Nod(long long int a, long long int b){
while(a!=0&&b!=0){
if (a>b)a%=b;
else b%=a;
}
return a+b;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
     long long int a,b,c,d,e;
     int n;
    cin>>n;
    while(n--){
        cin>>a>>b>>c;
        if (a!=0){
            d=Nod(a,b);
            b/=d;
            c=Nod(b,c);
        while(c!=1){
            while (b%c==0)b/=c;
            c=Nod(b,c);
        }
        if (b!=1)cout<<"Infinite\n";
        else cout<<"Finite\n";
        }
        else cout<<"Finite\n";
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(long long int a, long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long int a,b,c,d,e,n;
    cin>>n;
    for ( long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    if (a!=0){
    d=Nod(a,b);
    b/=d;
    c=Nod(b,c);
    while(c!=1){
        while (b%c==0)b/=c;
        c=Nod(b,c);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
    }
    else cout<<"Infinite\n";
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(unsigned long long int a, unsigned long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    unsigned long long int a,b,c,d,e,n;
    cin>>n;
    for (unsigned long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    d=Nod(a,b);
    b/=d;
    e=Nod(b,c);
    while(e!=1){
        b/=e;
        e=Nod(b,e);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(long long int a, long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long int a,b,c,d,e,n;
    cin>>n;
    for ( long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    if (a!=0){
    d=Nod(a,b);
    b/=d;
    c=Nod(b,c);
    while(c!=1){
        while (b%c==0)b/=c;
        c=Nod(b,c);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
    else cout<<"Infinite\n";
    }
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(long long int a, long long int b){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long int a,b,c,d,e,n;
    cin>>n;
    for ( long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    d=Nod(a,b);
    b/=d;
    c=Nod(b,c);
    while(c!=1){
        while (b%c==0)b/=c;
        c=Nod(b,c);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
unsigned long long int Nod(long long int a, long long int b){
if (a!=0){
while(a!=b){
if (a>=b)a-=b;
else b-=a;
}
return a;
}
else return 1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long int a,b,c,d,e,n;
    cin>>n;
    for ( long long int i=0;i<n;++i){
    cin>>a>>b>>c;
    d=Nod(a,b);
    b/=d;
    c=Nod(b,c);
    while(c!=1){
        while (b%c==0)b/=c;
        c=Nod(b,c);
    }
    if (b!=1)cout<<"Infinite\n";
    else cout<<"Finite\n";
    }
}


//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
typedef  long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int main()
{
	int n; cin >> n; ll p, q, b;
	for (int i = 0; i < n; i++) {
		cin >> p >> q >> b;
		q /= gcd(p, q);
		ll d = gcd(q, b);
		while (d != 1) {

			while (q%d == 0) {
				q /= d;
			}
			d = gcd(q, b);
		}
		if (q == 1) {
			printf("Finite\n");
		}
		else {
			printf("Infinite\n");
		}
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
typedef  long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int main()
{
	int n; cin >> n; ll p, q, b;
	for (int i = 0; i < n; i++) {

		scanf("%lld", "%lld", "%lld", &p, &q, &b);
		q /= gcd(p, q);
		ll d = gcd(q, b);
		while (d != 1) {

			while (q%d == 0) {
				q /= d;
			}
			b = d;
			d = gcd(q, b);
		}
		if (q == 1) {
			printf("Finite\n");
		}
		else {
			printf("Infinite\n");
		}
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
typedef  long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int main()
{
	int n; cin >> n; ll p, q, b;
	for (int i = 0; i < n; i++) {
		cin >> p >> q >> b;
		q /= gcd(p, q);
		ll d = gcd(q, b);
		while (d != 1) {

			q /= d;
			d = gcd(q, b);
		}
		if (q == 1) {
			printf("Finite\n");
		}
		else {
			printf("Infinite\n");
		}
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
typedef  long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int main()
{
	int n; cin >> n; ll p, q, b;
	for (int i = 0; i < n; i++) {
		cin >> p >> q >> b;
		q /= gcd(p, q);
		ll d = gcd(q, b);
		while (d != 1) {

			while (q%d == 0) {
				q /= d;
			}
			b = d;
			d = gcd(q, b);
		}
		if (q == 1) {
			printf("Finite\n");
		}
		else {
			printf("Infinite\n");
		}
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
typedef unsigned long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int main()
{
	int n; cin >> n; ll p, q, b;
	for (int i = 0; i < n; i++) {
		cin >> p >> q >> b;
		q /= gcd(p, q);
		ll d = gcd(q, b);
		while (d != 1) {

			q /= d;
			d = gcd(q, b);
		}
		if (q == 1) {
			printf("Finite\n");
		}
		else {
			printf("Infinite\n");
		}
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
typedef  long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int main()
{
	int n; cin >> n; ll p, q, b;
	for (int i = 0; i < n; i++) {

		scanf("%lld%lld%lld", &p, &q, &b);
		q /= gcd(p, q);
		ll d = gcd(q, b);
		while (d != 1) {

			while (q%d == 0) {
				q /= d;
			}
			b = d;
			d = gcd(q, b);
		}
		if (q == 1) {
			printf("Finite\n");
		}
		else {
			printf("Infinite\n");
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t; cin >> t;
	while(t --) {
		int p, q, k; cin >> p >> q >> k;
		p %= q;
		if(p == 0) cout << "Finite\n";
		else {
			q /= __gcd(p, q);
			while(q > 1) {
				int Yeee = __gcd(q, k);
				if(Yeee == 1) break;
				q /= Yeee;
			}
			if(q == 1) cout << "Finite\n";
			else cout << "Infinite\n";
		}
	}
}


#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
int gcd(int a, int b) {
	if(a == 0 or b == 0) return a + b;
	return gcd(b, a % b);
}
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t; cin >> t;
	while(t --) {
		int p, q, k; cin >> p >> q >> k;
		p %= q;
		if(p == 0) cout << "Finite\n";
		else {
			q /= gcd(p, q);
			while(q > 1) {
				int Yeee = gcd(q, k);
				if(Yeee == 1) break;
				while(q % Yeee == 0) q /= Yeee;
			}
			if(q == 1) cout << "Finite\n";
			else cout << "Infinite\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
main () {
	int t; cin >> t;
	while(t --) {
		int p, q, k; cin >> p >> q >> k;
		p %= q;
		if(p == 0) cout << "Finite\n";
		else {
			int GG = __gcd(p, q);
			p /= GG;
			q /= GG;
			while(q > 1) {
				int Yeee = __gcd(q, k);
				if(Yeee == 1) break;
				q /= Yeee;
			}
			if(q == 1) cout << "Finite\n";
			else cout << "Infinite\n";
		}
	}
}


#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t; cin >> t;
	while(t --) {
		int p, q, k; cin >> p >> q >> k;
		p %= q;
		if(p == 0) cout << "Finite\n";
		else {
			q /= __gcd(p, q);
			while(q > 1) {
				int Yeee = __gcd(q, k);
				if(Yeee == 1) break;
				q /= Yeee;
			}
			if(q == 1) cout << "Finite\n";
			else cout << "Infinite\n";
		}
	}
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main () {
	int t; cin >> t;
	while(t --) {
		int p, q, k; cin >> p >> q >> k;
		p %= q;
		if(p == 0) cout << "Finite\n";
		else {
			int GG = __gcd(p, q);
			p /= GG;
			q /= GG;
			while(q > 1) {
				int Yeee = __gcd(q, k);
				if(Yeee == 1) break;
				q /= Yeee;
			}
			if(q == 1) cout << "Finite\n";
			else cout << "Infinite\n";
		}
	}
}


#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
int gcd(int a, int b) {
	if(a == 0 or b == 0) return a + b;
	return gcd(b, a % b);
}
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t; cin >> t;
	while(t --) {
		int p, q, k; cin >> p >> q >> k;
		p %= q;
		if(p == 0) cout << "Finite\n";
		else {
			q /= gcd(p, q);
			while(q > 1) {
				int Yeee = gcd(q, k);
				if(Yeee == 1) break;
				q /= Yeee;
			}
			if(q == 1) cout << "Finite\n";
			else cout << "Infinite\n";
		}
	}
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 998244353
#define endl "\n"
#define maxx 9223372036854775807
using namespace std;
int main()
{
     boost;
     ll T;
     cin>>T;
     while(T--)
     {
          ll p,q,b;
          cin>>p>>q>>b;
          if(p == 0)  {cout<<"Finite"<<endl;continue;}
          ll g = __gcd(p,q);
          q = q/g;
          b = __gcd(q,b);
          while(b!=1)
          {
               while(q%b == 0)  q /= b;
               b = __gcd(q,b);
          }
          if(q == 1)  cout<<"Finite"<<endl;
          else  cout<<"Infinite"<<endl;
     }
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 998244353
#define endl "\n"
#define maxx 9223372036854775807
using namespace std;
int main()
{
    ll T;
    cin>>T;
    while(T--)
    {
        ll p,q,b;
        cin>>p>>q>>b;
        ll g = __gcd(p,q);
        p = p/g;
        q = q/g;
        g = __gcd(b,q);
        if(q == 1)  cout<<"Finite";
        else if(b%g == 0 && q%g == 0 && g!=1)  cout<<"Finite";
        else  cout<<"Infinite";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 998244353
#define endl "\n"
#define maxx 9223372036854775807
using namespace std;
int main()
{
    ll T;
    cin>>T;
    while(T--)
    {
        ll p,q,b;
        cin>>p>>q>>b;
        ll g = __gcd(p,q);
        p = p/g;
        q = q/g;
        if(q == 1)  cout<<"Finite";
        else if(__gcd(b,q) == min(q,b))  cout<<"Finite";
        else  cout<<"Infinite";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 998244353
#define endl "\n"
#define maxx 9223372036854775807
using namespace std;
int main()
{
    ll T;
    cin>>T;
    while(T--)
    {
        ll p,q,b;
        cin>>p>>q>>b;
        ll g = __gcd(p,q);
        p = p/g;
        q = q/g;
        g = __gcd(b,q);
        while(q%g == 0 && g != 1)  q = q/g;
        if(q == 1)  cout<<"Finite";
        else if(__gcd(q,b) == min(q,b))  cout<<"Finite";
        else  cout<<"Infinite";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 998244353
#define endl "\n"
#define maxx 9223372036854775807
using namespace std;
int main()
{
    ll T;
    cin>>T;
    while(T--)
    {
        ll p,q,b;
        cin>>p>>q>>b;
        ll g = __gcd(p,q);
        p = p/g;
        q = q/g;
        g = __gcd(b,q);
        if(q == 1)  cout<<"Finite";
        else if(g == min(q,b))  cout<<"Finite";
        else  cout<<"Infinite";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],dis[125],vis[125];
set<pair<long long, long long> >edges;
vector<pair<long long, long long> >e;
vector<long long>adj[125];
map<long long, long long> m;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long a,b,d;
        cin>>a>>b>>d;
        if(__gcd(b,d)==1 && b!=1)
            cout<<"Infinite\n";
        else
            cout<<"Finite\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],dis[125],vis[125];
set<pair<long long, long long> >edges;
vector<pair<long long, long long> >e;
vector<long long>adj[125];
map<long long, long long> m;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        long long a,b,d;
        cin>>a>>b>>d;
        long long x=__gcd(a,b);
        a/=x;
        b/=x;
        d=__gcd(b,d);
        while(d!=1)
        {
            b/=d;
            d=__gcd(d,b);
        }
        if(b==1)
            cout<<"Finite\n";
        else
            cout<<"Infinite\n";
    }
}


#include <bits/stdc++.h>
using namespace std;

//.define
//#define FILE_IN_OUT
#define RET(_x)                       return std::cout << (_x), 0;
#define all(_obj)                     std::begin(_obj), std::end(_obj)
#define fori(_iterator, _begin, _end) for (int _iterator = (_begin); _iterator < (_end); ++_iterator)
#define forr(_iterator, _begin, _end) for (int _iterator = (_begin); _iterator >= (_end); --_iterator)
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>(std::size(_obj))
#define endl                          "\n"
template<typename Tp>
inline void outarr(Tp _array, const std::size_t _N, const char* _delim = " ") {
    Tp end = _array + _N;
    for (Tp current = _array; current != end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = INT_MAX;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
int UUU = -1;

class Trie {
private:

    const char FIRST_ABC = 'a';

    struct Node {
        static const size_t ABC_N = 26;
        static const int    EMPTY = -1;

        int  cnt = 0;
        bool is_term = false;
        int  next[ABC_N];

        Node() {
            memset(next, EMPTY, sizeof(next));
        }
    };

    vector<Node> trie_;

    int convert(const char k) const {
        return k - FIRST_ABC;
    }

public:

    Trie()
        : trie_(vector<Node>(1)) {
        trie_[0].cnt = 1;
    }

    Trie(const size_t n)
        : trie_(vector<Node>(1)) {
        trie_[0].cnt = 1;
        trie_.reserve(n);
    }

    void append(string_view s) {
        int vertex = 0;
        for (const char p : s) {
            int ch = convert(p);
            ++trie_[vertex].cnt;
            if (trie_[vertex].next[ch] == Node::EMPTY) {
                trie_[vertex].next[ch] = trie_.size();
                trie_.emplace_back();
            }
            vertex = trie_[vertex].next[ch];
        }
        trie_[vertex].is_term = true;
    }

    int find(string_view s) const {
        int vertex = 0;
        int cntLet = 0;
        UUU = s.size();
        for (int i = 0; i < (int)s.size(); ++i) {
            int ch = convert(s[i]);
            if (trie_[vertex].next[ch] == Node::EMPTY) {
                if (!trie_[vertex].is_term) {
                    return -1;
                }
                return trie_[vertex].cnt == 0 && cntLet < i ? UUU = i, cntLet : -1;
            }
            if (trie_[vertex].cnt > 1 || trie_[vertex].is_term) {
                ++cntLet;
            }
            vertex = trie_[vertex].next[ch];
        }
        return trie_[vertex].is_term ? cntLet : -1;
    }

    void clear() {
        trie_.clear();
        trie_.resize(1);
    }

    void clear(const size_t n) {
        clear();
        trie_.reserve(n);
    }

};

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin  ("input.txt",  std::ios::in);
    std::ofstream cout ("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    Trie tr(500000);
    int ans = 0;
    for (string t, s; getline(cin, t);) {
        loop(sz(t)) {
            if (!isalpha(t[i])) {
                ++ans;
                if (!s.empty()) {
//                    cout << "S: " << s << endl;
                    int cnt = tr.find(s);
                    if (cnt == -1) {
                        ans += s.size();
                    } else if (cnt == sz(s)) {
                        ans += sz(s);
                    } else {
                        ans += cnt + 1;
                    }
                    if (cnt == -1 || UUU != sz(s)) {
                        tr.append(s);
                        ans += sz(s) - UUU;
                    }
//                    cout << "UUU: " << UUU << " " << cnt << " " << ans << endl;
                    s.clear();
                }
                continue;
            }
            s += t[i];
        }
        if (!s.empty()) {
//                    cout << "S: " << s << endl;
            int cnt = tr.find(s);
            if (cnt == -1) {
                ans += s.size();
            } else if (cnt == sz(s)) {
                ans += sz(s);
            } else {
                ans += cnt + 1;
            }
            if (cnt == -1 || UUU != sz(s)) {
                tr.append(s);
                ans += sz(s) - UUU;
            }
//                    cout << "UUU: " << UUU << " " << cnt << " " << ans << endl;
            s.clear();
        }
        ++ans;
//        cout << "T: " << sz(t) << endl << t << endl << " " << ans << endl;
    }

    cout << ans << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}


#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int cnt, m = 0;
string s, s1;

struct node {
	node *ch[26];
	node() {
		for (int i = 0; i < 26; i++)
			ch[i] = NULL;
	}
	int deg = 0;
	bool end = false;
}*tree[26];

int check(string s) {
	int i = 0, d1 = 0, d2 = 0;
	node *v = tree[s[0]-'a'];

	while (v != NULL && i < s.size() - 1 && v->deg > 1) {
		v = v->ch[s[i + 1] - 'a'];
		i++;
	}
	if (v == NULL || i>=s.size()-1)
		return s.size();
	d1 = i + 1;

	while (v != NULL && i < s.size() - 1 && v->end == false) {
		v = v->ch[s[i + 1] - 'a'];
		i++;
	}
	if (v == NULL || (v!=NULL && v->end == false))
		return s.size();
	d2 = i + 1;

	return min(s.size(), d1 + 1 + s.size() - d2);
}

int ind;
void add(string &s, int i, node &*v) {
	if (i < s.size() - 1) {
		if (v->ch[s[i + 1] - 'a'] == NULL)
			v->ch[s[i + 1] - 'a'] = new node;
		add(s, i + 1, v->ch[s[i + 1] - 'a']);
	}
	if (i == s.size() - 1) {
		if (v->end) ind = 0;
		else ind = 1, v->end = 1;
	}
	v->deg += ind;
}

int main() {

	while (getline(cin, s1)) {
		int n = s1.size(), i = 0;
		while (i<n) {
			s = "";
			if (s1[i] >= 'a' && s1[i] <= 'z') {
				while (i<n && s1[i] >= 'a' && s1[i] <= 'z') {
					s += s1[i];
					i++;
				}

				cnt += check(s);
				ind = 0;
				if (tree[s[0] - 'a'] == NULL)
					tree[s[0] - 'a'] = new node;
				add(s, 0, tree[s[0] - 'a']);
			}
			if(i<n)
				cnt++;
			i++;
		}
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}


#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int cnt, m = 0;
string s, s1;

struct node {
	node *ch[26];
	node() {
		for (int i = 0; i < 26; i++)
			ch[i] = NULL;
	}
	int deg = 0;
	bool end = false;
}*tree[26];

int check(string s) {
	int i = 0, d1 = 0, d2 = 0;
	node *v = tree[s[0]-'a'];

	while (v != NULL && i < s.size() - 1 && v->deg > 1) {
		v = v->ch[s[i + 1] - 'a'];
		i++;
	}
	if (v == NULL || i>=s.size()-1)
		return s.size();
	d1 = i + 1;

	while (v != NULL && i < s.size() - 1 && v->end == false) {
		v = v->ch[s[i + 1] - 'a'];
		i++;
	}
	if (v == NULL || (v!=NULL && v->end == false))
		return s.size();
	d2 = i + 1;

	return min(s.size(), d1 + 1 + s.size() - d2);
}

int ind;
void add(string &s, int i, node *&v) {
	if (i < s.size() - 1) {
		if (v->ch[s[i + 1] - 'a'] == NULL)
			v->ch[s[i + 1] - 'a'] = new node;
		add(s, i + 1, v->ch[s[i + 1] - 'a']);
	}
	if (i == s.size() - 1) {
		if (v->end) ind = 0;
		else ind = 1, v->end = 1;
	}
	v->deg += ind;
}

int main() {

	while (getline(cin, s1)) {
		int n = s1.size(), i = 0;
		while (i<n) {
			s = "";
			if (s1[i] >= 'a' && s1[i] <= 'z') {
				while (i<n && s1[i] >= 'a' && s1[i] <= 'z') {
					s += s1[i];
					i++;
				}

				cnt += check(s);
				ind = 0;
				if (tree[s[0] - 'a'] == NULL)
					tree[s[0] - 'a'] = new node;
				add(s, 0, tree[s[0] - 'a']);
			}
			if(i<n)
				cnt++;
			i++;
		}
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}