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

public class  AyubFun619C{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private 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());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 1; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        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;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			int n = s.nextInt(), m = s.nextInt();
			int zeroes = n - m;
			long substrings = 1l * n * (n + 1) / 2;
			long size = zeroes / (m + 1);
			
			long subzero = size * (size + 1) / 2 * (m + 1) + (size + 1) * (zeroes % (m  + 1));
					
			str.append(substrings - subzero+"\n");		
			
			
		}
		System.out.println(str);
	}

	

}

