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

public class Solution {
	public static void main(String [] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine()); 
		while(t-->0) {
			String [] in = br.readLine().split(" ");
			int n = Integer.parseInt(in[0]);
			int m = Integer.parseInt(in[1]);
			int low = (n-m)/(m+1);
			int high = low+1;
			int highCount  = (n-m)%(m+1);
			int lowCount = m+1-highCount;
			int badPair = ((low*(low+1))/2)*lowCount;
			badPair+= ((high*(high+1))/2)*highCount;
			
			System.out.println( (n*(n+1))/2 - badPair );
			
		}
	}
}