#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long n,a,b,e,xd,yd,tqn,tqi,gc;
long long evalute(long long beg,long long ll){return (ll*(ll+1))/2LL*beg;}
long long diag(long long n,long long a,long long b){
if(!a)return 0;else
return n/((a*b/gc)/a)+1;
}
long long solve(long long n,long long a,long long b){
if(!a)return 0;
long long xd=n,yd=(n*a)/b;
long long ret=(xd+1)*(yd+1);
ret-=evalute(b/a,(n*a)/b);
ret-=solve((n*a)/b,b%a,a)-diag((n*a)/b,b%a,a);
return ret;
}
inline int read(){
int ch,fla=0,ret=0;
while(1){
ch=getchar();
if(ch<48)if(fla)return ret;else continue;
ret=10*ret+ch-48;
fla=1;
}
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
scanf("%lld",&tqn);
for(tqi=0;tqi<tqn;tqi++){
n=read();
a=read();
b=read();
gc=__gcd(a,b);
printf("%lld\n",solve(n,a,b));
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmxvbmcgbG9uZyBuLGEsYixlLHhkLHlkLHRxbix0cWksZ2M7Cgpsb25nIGxvbmcgZXZhbHV0ZShsb25nIGxvbmcgYmVnLGxvbmcgbG9uZyBsbCl7cmV0dXJuIChsbCoobGwrMSkpLzJMTCpiZWc7fQoKbG9uZyBsb25nIGRpYWcobG9uZyBsb25nIG4sbG9uZyBsb25nIGEsbG9uZyBsb25nIGIpewoJaWYoIWEpcmV0dXJuIDA7ZWxzZQoJcmV0dXJuIG4vKChhKmIvZ2MpL2EpKzE7Cn0KCmxvbmcgbG9uZyBzb2x2ZShsb25nIGxvbmcgbixsb25nIGxvbmcgYSxsb25nIGxvbmcgYil7CglpZighYSlyZXR1cm4gMDsKCglsb25nIGxvbmcgeGQ9bix5ZD0obiphKS9iOwoJbG9uZyBsb25nIHJldD0oeGQrMSk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