from math import gcd for _ in range(int(input())): x, a, b = map(int, input().split()) if a > b: a, b = b, a m = a*b//gcd(a, b) n = (x-1+m)//m*m c = (x-1+a)//a*a d = (x-1+b)//b*b if x == d: ans = 1 elif x == c or d <= c: ans = 2 else: ans = 3 print((ans+(n-d)//b*2)%998244353)