{ll @T;REP(T){ll @d,@A,@B,a,b,t;if(A)A--;a=A%--d;b=B%d;wt(((B/d-A/d)*d*(d+1)+b*b+b-a*a-a)/2);}}