import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class codechef {	
    public static void main(String args[]) throws Exception {
        FastReader in = new FastReader(System.in);
        int testcases=in.nextInt(),i;
        StringBuilder sb = new StringBuilder();
        start:while(testcases-->0) {
        	int n=in.nextInt(),m=in.nextInt();
            long p=((long)n*(long)(n+1))/2;
            if(m+1>=n-m) {
                sb.append(p-(n-m)).append("\n");
                continue start;
            }
            int x=(n-m)%(m+1);
            long k=(n-m)/(m+1),res=0;
            res=(k*(k+1))/2;
            res=res*(long)(m+1-x);
            res+=(((k+1)*(k+2))/2)*(long)x;
            sb.append(p-res).append("\n");
        }
        System.out.print(sb);
    }
}
class FastReader {
    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;
    FastReader(InputStream is) {
        in = is;
    }
    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }
    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c != 10 && c != 13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    char nextChar() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        return (char) c;
    }
    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}