import math import sys input = sys.stdin.readline t = int(input()) for _ in range(t): x,a,b = map(int,input().split()) if a == b: if x % a == 0: print(0) else: print(1) continue if(a > b): a,b = b,a lc = math.lcm(a,b) las = (x + lc - 1) // lc * lc y = las // a - x // a z = las // b - x // b if x % a == 0: print(2*z) else: print(2*z+1)