import math MOD = 998244353 def solve(): X, A, B = map(int, input().split()) A, B = sorted([A, B]) if A == B: if X % A == 0: print(1) else: print(2) return if A == 1: if X % B == 0: print(1) else: print(2) return ans = len({X, (X + A - 1) // A * A, (X + B - 1) // B * B}) X = (X + B - 1) // B * B if X % A == 0: print(ans) return gcd = math.gcd(A, B) lcm = A * B // gcd cnt_lcm = (X + lcm - 1) // lcm * lcm ans += 2 * (cnt_lcm - X + B - 1) // B - 1 print(ans) T = int(input()) for _ in range(T): solve()