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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class C {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            while(testNumber-->0){
            	long n = in.nextLong();
                long ones = in.nextLong();
                String a = "";
                long zeros = n-ones;
                BigInteger q = new BigInteger(Long.toString(n));
                q = q.multiply(q.add(new BigInteger("1")).divide(new BigInteger("2")));
                if(zeros<=ones){
                    q = q.subtract(new BigInteger(Long.toString(zeros)));
                    out.println(q);
                    // out.println(n*(n+1)/2 - zeros);
                }
                else if(ones == 0)
                    out.println(0);
                else{
                    long zeroRem = zeros - (ones - 1);
                    long zeroLeft = zeroRem/2;
                    long zeroRight = zeroRem - zeroLeft;
                    BigInteger zle = new BigInteger(Long.toString(zeroLeft));
                    BigInteger zri = new BigInteger(Long.toString(zeroRight));
                    BigInteger on = new BigInteger(Long.toString(ones-1));
                    
                    zri = zri.multiply(zri.add(new BigInteger("1")).divide(new BigInteger("2")));
                    zle = zle.multiply(zle.add(new BigInteger("1")).divide(new BigInteger("2")));
                    
                    BigInteger ansd = q.subtract(zri).subtract(zle).subtract(on);

                    // long ans = n*(n+1)/2 - (zeroRight*(zeroRight+1)/2) - (zeroLeft*(zeroLeft+1)/2) - ((ones - 1));
                    out.println(ansd);
                }
            }
        }
        public int lowerBound(ArrayList<Integer> a , int x){
        	int l = 0;
        	int r = a.size()-1;
        	if(a.get(l)>=x)
        		return -1;
        	if(a.get(r)<x)
        		return r;
        	int mid = -1;
        	while(l<=r){
        		mid = (l+r)/2;
        		if(a.get(mid) == x && a.get(mid-1)<x)
        			return mid-1;
        		else if(a.get(mid)>=x)
        			r = mid-1;
        		else if(a.get(mid)<x && a.get(mid+1)>=x)
        			return mid;
        		else if(a.get(mid)<x && a.get(mid+1)<x)
        			l = mid+1;
        	}
        	return mid;
        }
        public int upperBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int log(int x){
		    return (int) Math.ceil((Math.log(x) / Math.log(2)+10e-10));
		}
        public long gcd(long a , long b){
        	if(a<b){
        		long c = b;
        		b = a;
        		a = c;
        	}
        	if(a%b==0)
        		return b;
        	return gcd(b , a%b);
        }
        public void print(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }
        class Combine{
            int value , delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                return -1;
            }
        }
    }

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

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

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}