from math import gcd mod = 998244353 for _ in range(int(input())): X, A, B = map(int, input().split()) A, B = min(A, B), max(A, B) G = gcd(A, B) L = A * B // G mx = (X + L - 1) // L * L ca = (X + A - 1) // A * A cb = (X + B - 1) // B * B ans = 1 if X != cb: ans += 1 if X != ca and ca < cb: ans += 1 ans += (mx - cb) // B * 2 print(ans)