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 one = sc.nextInt();
            int zero = n - one;

            int diff = Math.abs(one-zero);

            if(diff == 0 || diff == 1) {
                int answer = n * (n+1) / 2;
                answer -= zero;
                System.out.println(answer);
            }

            else {
                if(one > zero) {
                    int answer = n * (n+1) / 2;
                    answer -= zero;
                    System.out.println(answer);
                } else {
                    if(one == 0) {
                        System.out.println(0);
                    } else {
                        int temp = zero - one;
                        if(n % 2 == 1)
                            temp++;

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