import java.util.*;
public class cf66
{
    public static void main(String ars[])
    {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        while(q-->0)
        {
            long n=sc.nextLong();
            long m=sc.nextLong();
            long y=(((n-m)%(m+1)));
            long x=((n-m)/(m+1));
            
           
           
            
            System.out.println((n*(n+1))/2-(y*((x+1)*(x+2))/2)+((m+1-y)*(x*(x+1))/2));
            
        }
    }
}