import math import sys input = sys.stdin.readline mod = 998244353 t = int(input()) for _ in range(t): x,a,b = map(int,input().split()) if a == b: if x % a == 0: print(1) else: print(2) continue if(a > b): a,b = b,a lc = math.lcm(a,b) if x % lc == 0: print(1) continue las = (x + lc - 1) // lc * lc y = las // a - x // a z = las // b - x // b if y == 1 and z == 1: print(2) elif (x + a) // a * a >= (x + b) // b * b: print(2*z%mod) else: print((2*z+1)%mod)