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();
		n--;
		long sum=0;
		while(k>0 && n>0) {
			sum+=(2*n);
			n-=2;
			k--;
		}
		if(k>0) {
		sum+=k;}
		System.out.println(sum);
	t--;
	}
	
}
	}
