import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int z = 0; z < t; z++) { long d = sc.nextInt(); long x = sc.nextInt(); long y = sc.nextInt(); long g = gcd(x, y); long gx = x / g; long gy = y / g; long ok = 0; long ng = d + 1; while (Math.abs(ok - ng) > 1) { long mid = (ok + ng) / 2; long nx = x + gy * mid; long ny = y - gx * mid; if (nx <= d && 0 <= ny) { ok = mid; } else { ng = mid; } } long bx = x + gy * ok; long by = y - gx * ok; long ans1 = Math.abs(x * by - bx * y); ok = 0; ng = d + 1; while (Math.abs(ok - ng) > 1) { long mid = (ok + ng) / 2; long nx = x - gy * mid; long ny = y + gx * mid; if (0 <= nx && ny <= d) { ok = mid; } else { ng = mid; } } bx = x - gy * ok; by = y + gx * ok; long ans2 = Math.abs(x * by - bx * y); System.out.println(Math.max(ans1, ans2)); } sc.close(); } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } }