import java.io.*;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


    public static void main(String[] args) throws IOException {

        int num =Integer.parseInt(br.readLine());

        for (int k=0; k<num; k++) {

            StringTokenizer st= new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int m = Integer.parseInt(st.nextToken());
            long answer=0;
            BigDecimal ex = new BigDecimal("0");
            BigDecimal nn = new BigDecimal(String.valueOf(n));
            BigDecimal one = new BigDecimal("1");
            BigDecimal two = new BigDecimal("2");

            if (m==0) answer=0;

            else if (n==1 && m==1) answer=1;

            else if (n==2 && m==1) answer=2;

            else if (n==2 && m==2) answer=3;

            else if (n>=3 && n%2==0) {

                ex=(nn.divide(two).multiply(nn.divide(two).add(one)));

                if (m>1){
                    ex.add(nn).subtract(two);
                    for (int i=1; i<m; i++) ex=ex.add(one);
                }

                System.out.println(ex);
                continue;

            }

            else if (n>=3 && n%2==1) {

                ex=(nn.add(one).divide(two)).multiply(nn.add(one).divide(two));

                if (m>1){
                    ex.add(nn).subtract(two);
                    for (int i=1; i<m; i++) ex=ex.add(one);
                }

                System.out.println(ex);
                continue;

            }


            bw.write(Long.toString(answer));
            bw.newLine();

        }



        bw.flush();


    }

}
