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

public class C
{
    void solve(FastIO io)
    {
        long n = io.nextInt();
        long m = io.nextInt();

        long zero = n - m;

        long len = zero / (m+1);
        long left = zero % (m+1);

        long ans = left * ((((len + 2) * (len + 1)) / 2));
        ans += (m+1 - left) * (((len * (len+1)) / 2));

        long total = (n * (n+1)) / 2;
        io.println(total - ans);
    }

    public static void main(String[] args)
    {
        FastIO io = new FastIO();
        int t = io.nextInt();

        for (int i = 0; i < t; i++)
            new C().solve(io);

        io.close();
    }

    static class FastIO extends PrintWriter
    {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        FastIO()
        {
            super(System.out);
        }

        public String next()
        {
            while (!st.hasMoreTokens())
            {
                try {
                    st = new StringTokenizer(r.readLine());
                } catch (Exception e) {
                    //TODO: handle exception
                }
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

        public double nextDouble()
        {
            return Double.parseDouble(next());
        }
    }
}

