import java.util.*;
public class Ayoub
{
    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 o=n/2;
            int zr=n-o;
            if(m>=o)
            {
                long ans= (n*(n+1)/2)-(zr-(m-o));
                System.out.println(ans);
            }
            else
            {
                int diff=o-m;
                int cont=0;
                if(n%2==0)
                cont=diff*2;
                else
                cont=diff*2+1;

                int pres=(n-cont)/2;

                long ans= ((n*(n+1)/2)- cont*(cont+1)/2) -pres;
                System.out.println(ans);

            }
            t--;
        }
    }
}