import math mod=998244353 def slv(): A,B,C=map(int,input().split()) ps=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] print(len(ps)) def calc(p:int)->int: a,b,c=A,B,C ca,cc=0,0 while a%p==0: a//=p ca+=1 while c%p==0: c//=p cc+=1 return 10**50 if cc==0 else (ca*b)//cc ret=10**50 for p in ps: ret=min(ret,calc(p)) tmp=0 while B>1: A=math.gcd(A,C) t=-1 a=A for i in range(1,21): if a%C==0: t=i break a*=A if t==-1:break tmp+=B//t B//=t A=a//C ret=min(ret,tmp) print(ret%mod) T=int(input()) while T: T-=1 slv()