import java.io.*;
import java.util.*;
import java.lang.*;

public class Rextester{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer();
        int t = Integer.parseInt(br.readLine());
        while(t-->0){
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());
            if(k==0){
                sb.append("0\n");
                continue;
            }
            long max = (long)n*(n+1);
            max/=2;
            if(n%2==0){
                if(k>=n/2){
                    sb.append(max-n+k).append("\n");
                }
                else{
                    int left = n-2*k+1;
                    int a = left%2==0?left/2:(left/2)+1;
                    int b = left/2;
                    long more = (long)a*(a+1);
                    more/=2;
                    more+=((long)b*(b+1))/2;
                    sb.append(max-k+1-more).append("\n");
                }
            }
            else{
                if(k>=(n-1)/2){
                    sb.append(max-n+k).append("\n");
                }
                else{
                    int left = n - 2*k +1;
                    int a = left%2==0?left/2:(left/2)+1;
                    int b = left/2;
                    long more = (long)a*(a+1);
                    more/=2;
                    more+=((long)b*(b+1))/2;
                    sb.append(max-k+1-more).append("\n");
                }
            }
        }
        br.close();
        System.out.println(sb);
    }
}
     