import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class medo
{
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in); 
		int t,i;
		t=sc.nextInt();
		while(t>0)
		{
			t--;
			long n=sc.nextInt();
			long m=sc.nextInt();
			if(n==m)
			{
				System.out.println(n*(n+1)/2);
				continue;
			}
			long ans=n*(n+1)/2;
			long m1=m+1;
			long n1=n-m;
			if(m1>=n1)
			{
				ans-=n1;
				System.out.println(ans);
			}
			else
			{
				long div= (long)Math.ceil((double)n1/m1);
				long num = (n1-m1)/(div-1);
				ans -= num * div*(div+1)/2;
				ans-= (m1-num)*(div)*(div-1)/2;
				System.out.println(ans);
			}
			
		}
	}
}