import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while(t-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int zero = n - m;
            int one = m;

            int answer = 0;
            if(one >= zero) {
                answer = n * (n+1) / 2;
                answer -= zero;
            } else {
                if(one > 0) {
                    int temp = one - 1;
                    int zero2 = zero - temp;
                    int left = zero2/2;
                    int right = zero2 - left;

                    answer = n * (n+1) / 2;
                    answer -= zero;
                    answer -= left * (left-1) / 2;
                    answer -= right * (right-1) / 2;
                }
            }
            System.out.println(answer);
        }
    }
}
