import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MainClass {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		
		int t = Integer.parseInt(br.readLine());
		for (; t > 0; t--) {
			String[] strs = br.readLine().split(" ");
			long n = Integer.parseInt(strs[0]);
			long m = Integer.parseInt(strs[1]);
			long z = n - m;
			long count = n * (n + 1) / 2;
			long p = z / (m + 1);
			count -= ((m + 1) - z % (m + 1)) * p * (p+1) / 2;
			count -= z % (m + 1) * (p+1)*(p+2) / 2;
			
			System.out.println(count);
		}
		
		br.close();
	}

}
