import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
//import java.util.TreeSet;

public class Main
 {
	public static void main(String Args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int t = Integer.parseInt(st.nextToken());
		StringBuilder str = new StringBuilder();
		while(t-->0)
		{
			
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			long v =(n*(long)(n+1))/2;
			long val =(n-k)/(k+1);
			long rem = (n-k)%(k+1);
			long fin = (rem*((val+1)*(val+2))/2)+(k+1-rem)*(val*(val+1))/2;
			str.append(v-fin+"\n");
		}
		System.out.println(str.toString());	
	}
 }