import java.util.Scanner;
// import java.util.ArrayList;
// import java.util.Arrays;
// import java.util.HashMap;
// import java.util.HashSet;



public class ans3{
    static int mod = (int)10e8;

    public static int lower(int arr[],int key){
        int low = 0;
        int high = arr.length-1;
        while(low < high){
            int mid = low + (high - low)/2;
            if(arr[mid] >= key){
                high = mid;
            }
            else{
                low = mid+1;
            }
        }
        return low;
    }

    public static int upper(int arr[],int key){
        int low = 0;
        int high = arr.length-1;
        while(low < high){
            int mid = low + (high - low+1)/2;
            if(arr[mid] <= key){
                low = mid;
            }
            else{
                high = mid-1;
            }
        }
        return low;
    }

    public static long help(long n){
        return (n*(n+1))/2;
    }

    public static void main(String args[]){
        Scanner scn = new Scanner(System.in);

        int test = scn.nextInt();
        StringBuilder sb = new StringBuilder();
        while(test-- > 0){
            long n = scn.nextLong();
            long m = scn.nextLong();

            long a = n - m;
            if(m == 0){
                sb.append(0);
                sb.append("\n");
                continue;
            }
            long b = 0;
            if(m >= a || m + 1 == a){
                sb.append(help(n) - a);
                sb.append("\n");
            }else{
                long c = a - m;
                if(c%2 == 0){
                    c /= 2;
                     b = help(c) + help(c+1);
                }else{
                    c /= 2;
                    c++;
                    b = help(c)*2;
                }
                sb.append(help(n) - b);
                sb.append("\n");
            }
        }
        System.out.println(sb);
    }
}