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 = 0 if X % A > 0: ans += 1 X = (X + A - 1) // A * A gcd = math.gcd(A, B) lcm = A * B // gcd cnt_lcm = (X + lcm - 1) // lcm * lcm cnt_A = (X + A - 1) // A * A ans += (cnt_lcm - X + B) // B * 2 print(ans) T = int(input()) for _ in range(T): solve()