from math import gcd t = int(input()) for _ in range(t): x,a,b = map(int,input().split()) if a == b: if (x % a == 0): print(1) else: print(2) else: if a > b: b,a = a,b lcm_ab = a*b//gcd(a,b) zlcm = (x+lcm_ab-1)//lcm_ab * lcm_ab z = lcm_ab // b la = (x+a-1)//a * a lb = (x+b-1)//b * b y = lb // b if lb > la: if (x % a != 0):print(2 * z - 2 * y + 2 + 1) else: print(2 * z - 2 * y + 2) else: if (x % b != 0):print(2 * z - 2 * y + 2) else: print(2 * z - 2 * y)