import java.util.*;

public class CF619{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int test=sc.nextInt();
		for(int t=0;t<test;t++){
			int n=sc.nextInt();
			int m=sc.nextInt();
			int sol=((n*(n+1))/2);
			int z=n-m;
			int k=z/(m+1);
			sol-=(((k*(k+1))/2)*(m+1))-((k+1)*(z%(m+1)));
			System.out.println(sol);
		}
	}
}