import java.util.*;
import java.io.*;

public class L {

	static int mod = (int) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer st = new StringTokenizer(br.readLine());
		int t = Integer.parseInt(st.nextToken());
		while (t-- > 0) {
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			int[] a = new int[n];
			int l = -1;
			int m = k;
			for (int i = 1; i < a.length && m > 0; i += 2) {
				a[i] = 1;
				l = i;
				m--;
			}
			long sum = 0;
			for (int i = 0; i <= l; i++) {
				sum += n - i - 1;
			}
			System.out.println(sum + k);
		}

		pw.flush();
	}

	static int maxl(int r, int g) {
		int s = 0;
		int e = 1000;
		int ans = -1;
		while (s <= e) {
			int mid = s + e >> 1;
			if (mid * (mid + 1) / 2 <= r + g) {
				ans = mid;
				s = mid + 1;
			} else
				e = mid - 1;

		}
		return ans;
	}
}
