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

public class Round619C {

	public static void solve() {
		int t = s.nextInt();
		while(t-- > 0) {
			long n = s.nextInt();
			long m = s.nextLong();
//			if(m == 0) {
//				out.println(((n * (n+1))/2L));
//				continue;
//			}
			long total = n * (n+1);
			total/=2L;
			n = n - m;
			long parts = n/(m+1);
			long rem = n%(m+1);
			long ans = ((parts * (parts+1))/2L) * (m + 1 - rem);
			long tempans = (((parts+1) * (parts+2))/2L) * (rem);
			ans += tempans;
			out.println(total - ans);
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}
