import java.io.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	static int tc;
 
	static void solve() throws Exception {
		long n = sc.nextLong(), one = sc.nextLong(), zero = n - one;
		long len = zero / (one + 1), rem = zero % (one + 1);
		long ans = n * (n + 1) / 2;
		ans -= (one + 1 - rem) * len * (len + 1) / 2;
		ans -= rem * (len + 1) * (len + 2) / 2;
		out.println(ans);
	}
 
	public static void main(String[] args) throws Exception {
		tc = sc.nextInt();
		while (tc-- > 0) {
			solve();
		}
		out.close();
	}
 
}
 
class Scanner {
	StringTokenizer st;
	BufferedReader br;
 
	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}
 
	public Scanner(String file) throws Exception {
		br = new BufferedReader(new FileReader(file));
	}
 
	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
 
	public String nextLine() throws IOException {
		return br.readLine();
	}
 
	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
 
	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
 
	public Long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}