ll@t;rep(t){ll@n,@a,@b,x=n/a;wt(n*x+x*~x/2a-floor_sum(n/b,a,b-a*b,n%b*-~-a));}