/*

I FOLLOW THE WAY OF THE RIGHT HONOURABLE JIM KWIK,
GOD BLESS YOU SIR

1.  I AM A 'NEWBIE' IN RATING
2.  I WILL FAIL MANY TIMES, BUT I WILL NOT FAIL TO LEARN FROM FAILURE
3.  I WILL NEVER SURRENDER MY GOAL, NO MATTER HOW MUCH I FAIL
4.  I WILL PROVE MY SKILLS WHEN THE TIME COMES
5.  I WILL ALWAYS KEEP TRYING

*/





import java.util.*;
import java.io.*;
public class A {













    static boolean tests = true;
    static void solve(){
       int n = in.nextInt();
       int m = in.nextInt();
       int left = n-m;
       int big = left % (m+1);
       int standard = left/(m+1);
       long ans = (long) (m + 1 - big) * standard * (standard + 1) /2;
       ans += (long) big * (standard + 1) * (standard + 2) /2;
       long total = (long)n*(n+1)/2;
       out.println(total-ans);
    }

























    static Reader in;
    static PrintWriter out;
    static int int_max = (int)1e9, mod = int_max+7;
    public static void main(String[] args){
        in = new Reader();
        out = new PrintWriter(System.out);
        int t = tests ? in.nextInt() : 1;
        while (t-- > 0) solve();
        out.close();
    }
    static class Reader{
        // Reader credited to SecondThread
        BufferedReader b;
        StringTokenizer s;
        Reader(){
            this.b = new BufferedReader(new InputStreamReader(System.in));
            this.s = new StringTokenizer("");
        }
        String next(){
            while (!s.hasMoreTokens())
                try{s = new StringTokenizer(b.readLine());
                }catch(IOException ignored){}
            return s.nextToken();
        }
        int nextInt(){return Integer.parseInt(next());}
        long nextLong(){return Long.parseLong(next());}
        double nextDouble(){return Double.parseDouble(next());}
        int[] ai(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = nextInt();
            return a;
        }
        long[] al(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; ++i)
                a[i] = nextLong();
            return a;
        }
    }
}