// This file is a "Hello, world!" in C++ language by GCC for wandbox. #include #include using namespace std; long long gcd(long a, long b) { if (b==0) return a; return gcd(b, a%b); } int main() { int T; cin >> T; while (T-->0) { int N, A, B; cin >> N >> A >> B; long long ans=0; { int top=N-A; int bottom=A-(A-N%A)%A; ans+=(long long)((top-bottom)/A+1)*(top+bottom)/2; } { int top=N-B; int bottom=B-(B-N%B)%B; ans+=(long long)((top-bottom)/B+1)*(top+bottom)/2; } int i=1; long long g=gcd(A, B); N/=g; A/=g; B/=g; if (A