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

public class test {
    static int[][] dir={{0,1},{1,0},{-1,0},{0,-1}};
   static class sort implements Comparator<long[]>
   {
        public int compare(long[] a,long[] b)
        {
            if(a[0]>b[0]) return 1;
            if(a[0]<b[0]) return -1;
            return 0;
        }
   }
   public static void print(Object o)
   {
     PrintWriter out = new PrintWriter(System.out);;;
    out.println(o.toString());
    out.flush();
   }
   public static int intIn(String st)
   {
      return Integer.parseInt(st);
   }
   
   
    public static long Dis(int a,int b,int[][] arr)
    {
        long sum =0l;
        for(int[] x : arr)
        {
            sum = sum + Math.abs(a-x[0]) +Math.abs(b-x[1]) + 0l;
        }
        return sum;
    }
    public static void pr(Object o)
    {
        System.out.println(o.toString());
    }
    public static long F(int a,int b)
    {
        return (1337317l)*a + (337133731l)*b;
    }
   
    public static int inInt(String s)
    {
        return Integer.parseInt(s);
    }
    public static long in(String s)
    {
        return Long.parseLong(s);
    }
    public static boolean F(int a,int[] arr)
    {
        PriorityQueue<Integer> pq=new PriorityQueue<>();
        int rem=0;
        for(int o=0;o<arr.length;o++)
        {
            if(arr[o] > 0)
            pq.add(-1*(arr[o]));
        rem += (arr[o]);
        }
        boolean bol=true;
        List<Integer> list=new ArrayList<>();//int rem=
        //pr(pq);
        while(pq.size() > 0)
        {
            int c=a;
            while(pq.size() > 0 && c>=0)
            {
                int x = pq.remove()*(-1);
                if((x-1) > 0)
                list.add(x-1);


                c--;
            }
            if(pq.size() == 0 && c>=0 && list.size()>0) 
            {
                bol=false;break;
            }
            c=0;int sz=list.size();
            while(c<sz)
            {
                if(list.get(c) > 0)
                pq.add(-1*(list.get(c)));
                //else rem--;
                c++;
            }
           // pr(pq);
            list.clear();
        }
        return bol;
        
        
    }

    public static void main (String[] args) throws Exception {
        
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        
        
        //int[] map=new int[1000001];
      
        int y=Integer.parseInt(bf.readLine());
        
        for(int h=0;h<y;h++)
        {

            
        
            String[] xlp = bf.readLine().split(" ");
            
            long n,a,k,l,r;
            n=in(xlp[0]);k=in(xlp[1]);
            /*k=Integer.parseInt(xlp[1]);
            l=Integer.parseInt(xlp[2]);
            r=Integer.parseInt(xlp[3]);
            */
            long m = (k+1);
            long g = (n-k+0l)/(m+0l);
            long mod = (n-k)%(m);
            long rem = (m-mod);
            long ans = (n+0l)*(n+1l);
            ans = (ans)/2;
            ans = ans  - (((g+1l)*(g+2l))/2)*mod -  (((g+0l)*(g+1l))/2)*rem;
            //pr(m+" "+g+" "+mod);
            pr(ans);

           
            

            

            
            
            
        }

    }
}
/*
1
28 94
14 8
6 5

*/


