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

public class Solution {
    public static int cycles = 0;

    public static int[] nextArray(FastReader sc1, int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc1.nextInt();
        }
        return arr;
    }

    public static void printMatrix(int[][] mat){
        for(int i=0; i<mat.length; i++){
            for(int j=0; j<mat[0].length; j++){
                System.out.print(mat[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println();
    }

    public static void dfs(int node, HashMap<Integer, HashSet<Integer>> tree, int[] vis, int[] dist){
        vis[node] = 1;
        if(tree.containsKey(node)){
            HashSet<Integer> set = tree.get(node);
            for(int ele : set){
                if(vis[ele] == 0){
                    dist[ele] = dist[node]+1;
                    dfs(ele, tree, vis, dist);
                }
            }
        }
    }

    public static void addEdge(int u, int v, HashMap<Integer, HashSet<Integer>> tree){
        if(tree.containsKey(u)){
            HashSet<Integer> set = tree.get(u);
            set.add(v);
            tree.put(u, set);
        }
        else{
            HashSet<Integer> set = new HashSet<>();
            set.add(v);
            tree.put(u, set);
        }
    }

    public static void main(String[] args) {
        FastReader sc1 = new FastReader();
        StringBuilder sb = new StringBuilder();

        int tc = Integer.parseInt(sc1.nextLine());
        int ch = 0;

        while(ch<tc){
            long n = sc1.nextInt();
            long m = sc1.nextInt();
            long nz = n-m;
            long osub = 0;
            long tot = n*(n+1L)/2L;
            if(nz-1 <= m){
                osub = tot - nz;
            }
            else{
                if(nz%(m+1L) == 0){
                    long size = nz/(m+1L);
                    osub = tot - (m+1L)* ( (size*(size+1L)) / 2L);
                }
                else{
                    long size = nz/(m+1L) + 1L;
                    long left = size*(m+1L) - nz;
                    osub = tot - m * ( (size*(size+1L)) / 2L) - ( (left*(left+1L)) / 2L) ;
                }
            }

            sb.append(osub+"\n");
            ch++;
        }

        System.out.print(sb.toString());
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}