import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class combinotorics {
	public static void main(String[] args) {
	Scanner s=new Scanner(System.in);
	int t=s.nextInt();
	while(t>0) {
		int n=s.nextInt();
		int k=s.nextInt();
		if(k<=n/2) {
			long sum=0;
			n--;
			while(k>0 && n>0) {
				sum+=(2*n);
				n-=2;
				k--;
			}
			System.out.println(sum);
		}else {
			long sum=n;
			n-=2;
			k--;
			while(k>0 && n>0) {
				sum+=(2*n);
				n-=2;
				k--;
			}
			System.out.println(sum);
			
		}
	t--;
	}
	
}
	}
