import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class r619 {
	public static void main (String []args) throws IOException {
		 PrintWriter pw =new PrintWriter(System.out);
	Scanner sc=new Scanner(System.in); 
  int t=sc.nextInt();
  for(int k=0;k<t;k++) {
	  long n=sc.nextLong();
	  long a=sc.nextLong();
	  long f=a>(n/2+n%2)?n-a:n-(2*a);
	  long total=((long)(n*(n-1))/2-(((long)(f)*(f-1)))/2)+a;
	  long total2=((long) (n*(n+1)))/2;
	if(a==0)pw.println(0); else pw.println(total);
	 }
	  
  pw.flush();

  
}
	 static class Scanner {
		 
			StringTokenizer st;
			BufferedReader br;

			public Scanner(InputStream system) {
				br = new BufferedReader(new InputStreamReader(system));
			}

			public Scanner(String file) throws Exception {
				br = new BufferedReader(new FileReader(file));
			}

			public String next() throws IOException {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			}

			public String nextLine() throws IOException {
				return br.readLine();
			}

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

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

			public char nextChar() throws IOException {
				return next().charAt(0);
			}

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

			public boolean ready() throws IOException {
				return br.ready();
			}

			public void waitForInput() throws InterruptedException {
				Thread.sleep(3000);
			}}
}
