#include long long int gcd(long long int a, long long int b) { long long int r = a % b; while (r > 0) { a = b; b = r; r = a % b; } return b; } void solve() { long long int d, x, y; scanf("%lld %lld %lld", &d, &x, &y); if (x < y) { long long int f = x; x = y; y = f; } if (y == 0) { printf("%lld\n", x * d); return; } long long int g = gcd(y, x); long long int dx = y / g, dy = x / g; long long int s, t, c; c = (d - y) / dy; if (c > x / dx) c = x / dx; s = x - c * dx; t = y + c * dy; printf("%lld\n", x * t - y * s); return; } int main() { int t; scanf("%d", &t); for (; t > 0; t--) solve(); return 0; }