import math def divceil(a, b): return (a + b - 1) // b def solve(x, a, b): a, b = min(a, b), max(a, b) g = math.gcd(a, b) k = a // g x %= a * b // g n, m = divceil(x, a), divceil(x, b) if a == 1 or a == b: return 1 if x == m * b else 2 ans = 0 if not(x == n * a or x == m * b): ans += 1 if not(n * a < m * b): ans -= 1 ans += 2 * (k - m + 1) return ans t = int(input()) for _ in range(t): x, a, b = map(int, input().split()) print(solve(x, a, b) % 998244353)