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

/**
 *
 * @author Saju
 *
 */

public class Main {

	private static int dx[] = { 1, 0, -1, 0 };
	private static int dy[] = { 0, -1, 0, 1 };

	private static final long INF = Long.MAX_VALUE;
	private static final int INT_INF = Integer.MAX_VALUE;
	private static final long NEG_INF = Long.MIN_VALUE;
	private static final int NEG_INT_INF = Integer.MIN_VALUE;
	private static final double EPSILON = 1e-10;

	private static final int MAX = 1007;
	private static final long MOD = 1000000007;

	private static final int MAXN = 100007;
	private static final int MAXA = 10000009;
	private static final int MAXLOG = 22;

	public static void main(String[] args) {

		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

/*



*/
		
		
		
		int test = in.nextInt();
		for (int t = 1; t <= test; t++) {
			long n = in.nextLong();
			long one = in.nextLong();
			long zero = n - one;
			
			if(n % 2 == 0) {
				if((n / 2) >= zero) {
					long val = (n / 2) * (n + 1);
					val -= zero;
					System.out.println(val);
				}
				else {
//					System.out.println("H");
					if(zero == n) {
						System.out.println("0");
					}
					else if(zero % one == 0) {
						long val = n * ((n + 1) / 2);
						long zeroC = zero / one;
						long zeroV = (zeroC * (zeroC + 1)) / 2;
						zeroV = zeroV * (long)(one);
						System.out.println(val - zeroV);
					}
					else {
						long val = n * ((n + 1) / 2);
						long zeroC = zero / one;
						long zeroV = (zeroC * (zeroC + 1)) / 2;
						zeroV = zeroV * (long)(one);
						long rem = zero % one;
						long remV = (rem * (rem + 1)) / 2;
						System.out.println(val - zeroV - remV);
					}
				}
			}
			else {
				if(zero <= ceil(n, 2)) {
					long val = (n) * ((n + 1) / 2);
					val -= zero;
					System.out.println(val);
				}
				else {
//					System.out.println("H1");
					if(zero == n) {
						System.out.println("0");
					}
					else if(zero % one == 0) {
						long val = n * ((n + 1) / 2);
						long zeroC = zero / one;
						long zeroV = (zeroC * (zeroC + 1)) / 2;
						zeroV = zeroV * (long)(one);
						System.out.println(val - zeroV);
					}
					else {
						long val = n * ((n + 1) / 2);
						long zeroC = zero / one;
						long zeroV = (zeroC * (zeroC + 1)) / 2;
						zeroV = zeroV * (long)(one);
						long rem = zero % one;
						long remV = (rem * (rem + 1)) / 2;
						System.out.println(val - zeroV - remV);
					}
				}
			}
		}
		
		out.flush();
		out.close();
		System.exit(0);
	}

	

	private static long ceil(long d, long div) {
		if(d % div == 0) {
			return d / div;
		}
		return (d + div) / div;
	}



	private static boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		String str1 = sb.reverse().toString();
		return str.equals(str1);
	}

	private static String reverseString(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		return sb.reverse().toString();
	}

	private static double distance(Point p1, Point p2) {
		long divx = p2.x - p1.x;
		long divy = p2.y - p1.y;
		divx = divx * divx;
		divy = divy * divy;
		return Math.sqrt(divx + divy);
	}

	private static String getBinaryStr(int n, int j) {
		String str = Integer.toBinaryString(n);
		int k = str.length();
		for (int i = 1; i <= j - k; i++) {
			str = "0" + str;
		}

		return str;
	}

	// O(log(max(A,M)))
	static long modInverse(long a, long m) {
		extendedEuclid(a, m);
		return (x % m + m) % m;
	}

	static long x;
	static long y;
	static long gcdx;

	private static void extendedEuclid(long a, long b) {
		if (b == 0) {
			gcdx = a;
			x = 1;
			y = 0;
		} else {
			extendedEuclid(b, a % b);
			long temp = x;
			x = y;
			y = temp - ((a / b) * y);
		}
	}

	private static void generatePrime(int n) {
		// O(NloglogN)
		boolean arr[] = new boolean[n + 5];
		Arrays.fill(arr, true);
		for (int i = 2; i * i <= n; i++) {
			if (arr[i] == true) {
				for (int j = i * i; j <= n; j += i) {
					arr[j] = false;
				}
			}
		}
		int count = 0;
		int start = 0;
		for (int i = 2; i <= n; i++) {
			if (arr[i] == true) {
				// System.out.println(i + " ");
				count++;
			}
			if (count == (start * 100) + 1) {
				// System.out.println(i);
				start++;
			}
		}
		System.out.println();
		System.out.println(count);

	}

	private static Map<Long, Long> primeFactorization(long n, long m) {
		Map<Long, Long> map = new HashMap<>();

		for (long i = 2; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				long count = 0;
				while (n % i == 0) {
					count++;
					n = n / i;
				}
				long val = count * m;
				map.put(i, val);
				// System.out.println("i: " + i + ", count: " + count);
			}

		}
		if (n != 1) {
			// System.out.println(n);
			map.put(n, m);
		}
		return map;
	}

	private static class Point {
		long x;
		long y;

		Point(long x, long y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public boolean equals(Object obj) {
			Point ob = (Point) obj;
			if (this.x == ob.x && this.y == ob.y) {
				return true;
			}
			return false;

		}

		@Override
		public String toString() {
			return this.x + " " + this.y;
		}

		@Override
		public int hashCode() {
			return 0;
		}
	}

	private static long pow(int base, int pow) {
		long val = 1L;
		for (int i = 1; i <= pow; i++) {
			val *= base;
		}
		return val;
	}

	private static int log(int x, int base) {
		return (int) (Math.log(x) / Math.log(base));
	}

	private static int log(long x, int base) {
		return (int) (Math.log(x) / Math.log(base));
	}

	private static long max(long a, long b) {
		if (a >= b) {
			return a;
		}
		return b;
	}

	private static long abs(long a) {
		if (a < 0) {
			return -a;
		}
		return a;
	}

	private static int abs(int a) {
		if (a < 0) {
			return -a;
		}
		return a;
	}

	private static int max(int a, int b) {
		if (a >= b) {
			return a;
		}
		return b;
	}

	private static int min(int a, int b) {
		if (a <= b) {
			return a;
		}
		return b;
	}

	private static long min(long a, long b) {
		if (a <= b) {
			return a;
		}
		return b;
	}

	private static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	private static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	private static long bigMod(long n, long k, long m) {

		long ans = 1;
		while (k > 0) {
			if ((k & 1) == 1) {
				ans = (ans * n) % m;
			}
			n = (n * n) % m;
			k >>= 1;
		}
		return ans;
	}

	/*
	 * Returns an iterator pointing to the first element in the range [first, last]
	 * which does not compare less than val.
	 * 
	 */
	private static int lowerBoundNew(long[] arr, long num) {
		int start = 0;
		int end = arr.length - 1;
		int index = 0;
		int len = arr.length;
		int mid = 0;
		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			if (arr[mid] > num) {
				end = mid - 1;
			} else if (arr[mid] < num) {
				start = mid + 1;
			} else {
				while (mid >= 0 && arr[mid] == num) {
					mid--;
				}
				return mid + 1;
			}
		}
		if (arr[mid] < num) {
			return mid + 1;
		}
		return mid;
	}

	/*
	 * upper_bound() is a standard library function in C++ defined in the header .
	 * It returns an iterator pointing to the first element in the range [first,
	 * last) that is greater than value, or last if no such element is found
	 * 
	 */
	private static int upperBoundNew(long arr[], long num) {

		int start = 0;
		int end = arr.length - 1;
		int index = 0;
		int len = arr.length;
		int mid = 0;
		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			long val = arr[mid];
			if (val > num) {
				end = mid - 1;
			} else if (val < num) {
				start = mid + 1;
			} else {
				while (mid < len && arr[mid] == num) {
					mid++;
				}
				if (mid == len - 1 && arr[mid] == num) {
					return mid + 1;
				} else {
					return mid;
				}
			}
		}
		if (arr[mid] < num) {
			return mid + 1;
		}
		return mid;
	}

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public String next() {
			try {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					tokenizer = new StringTokenizer(reader.readLine());

				}
			} catch (IOException e) {
				return null;
			}
			return tokenizer.nextToken();
		}

		public String nextLine() {
			String line = null;
			try {
				tokenizer = null;
				line = reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return line;
		}

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

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

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

		public boolean hasNext() {
			try {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					tokenizer = new StringTokenizer(reader.readLine());
				}
			} catch (Exception e) {
				return false;
			}
			return true;
		}
	}
}