import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C1301 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        StringTokenizer st;
        for (int t = Integer.parseInt(br.readLine()); t-- > 0; ) {
            st = new StringTokenizer(br.readLine());
            long n = Long.parseLong(st.nextToken());
            long m = Long.parseLong(st.nextToken());
            long total = (n * (n + 1)) / 2;
            long num0Seq = m + 1;
            long len0 = (n - m) / num0Seq;
            long remaining0 = (n - m) % num0Seq;
            long ans = total - ((len0 * (len0 + 1)) / 2) * num0Seq - (len0 + 1) * (remaining0);
            out.println(ans);
        }
        out.close();
    }
}
