import java.util.*;
import java.io.*;
public class GFG {
  	public static void main (String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int t=sc.nextInt();
	    while (t-->0){ 
	    long n=sc.nextLong();
	    long m=sc.nextLong();
	    long k=(n*(n+1))/2;
	    long a=(long)Math.min(m,n-m);
	    k=k-a;
	    a=n-m-a;
	    k=k-(a*(a+1))/2;
	    System.out.println(k);
	    }
  	}
}