#include using namespace std; using ll = long long; void solve(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int tc; cin >> tc; for (int tt = 0; tt < tc; tt++) solve(); return 0; } void solve() { ll d, x, y; cin >> d >> x >> y; if (x > y) swap(x, y); if (x == 0) { cout << d * y << "\n"; return; } ll dx = y / gcd(x, y), dy = x / gcd(x, y); ll l = max(min((d - x) / dx, y / dy), min(x / dx, (d - y) / dy)); ll x0 = x - l * dx, y0 = y + l * dy; ll ans = abs(x * y0 - y * x0); cout << ans << "\n"; }