////////////////////---------------------------SHUBHAM CHAUDHARI-------------------------------///////////////////////


import java.util.*;

public class Main {
    static int mod=1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        StringBuilder res=new StringBuilder();
        while (t-->0)
        {
            long n=in.nextLong();
            long one=in.nextLong();
            long zero=n-one;
            long g=one+1;
            long k=zero/g;
            long ans=n*(n+1)/2-k*(k+1)/2*g-(k+1)*(zero%g);
            res.append(ans+"\n");
        }
        System.out.println(res);

    }

    static class Node{
        int left;
        int right;
        public Node()
        {
            left=-1;
            right=-1;
        }
    }

}