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

public class C {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int t = sc.nextInt();
		while(t-->0) {
			long n = sc.nextLong();
			long m = sc.nextLong();
			long ans = (n) * (n+1) / 2;
			long z = n - m;
			long g = m + 1;
			long k = z / g;
			ans -= ((g) * k * (k+1) / 2 + (z % g) * (k+1));
			System.out.println(ans);
		}
	}
	// credit SecondThread
	// test if input is cause for tle
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}
