def get(a: int, b: int, c: int, d: int) -> int: res = 0 # a を d で割り切れるだけ割って、その回数を res に加える while a % d == 0: res += 1 a //= d ta = 1 for i in range(min(c, 150)): ta *= b if ta % d == 0: x = 0 while ta % d == 0: x += 1 ta //= d sub_c = c // (i + 1) sub_res = get(a * pow(b, c % (i + 1)), ta, sub_c, d) return x * sub_c + sub_res return res from math import gcd def check(a: int, b: int) -> int: g = gcd(a, b) while True: gg = gcd(a, g) if gg == 1: break a //= gg return a def main(): t = int(input()) for _ in range(t): A, B, C = map(int, input().split()) A //= check(A,C) print(get(1, A, B, C)%998244353) if __name__ == "__main__": main()