import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

	public static void fact(int n){
		int res[] = new int[500];   
        res[0] = 1; 
        int res_size = 1; 
        for (int x = 2; x <= n; x++) 
            res_size = multiply(x, res, res_size); 
        for (int i = res_size - 1; i >= 0; i--) 
            System.out.print(res[i]); 
	}
	public static int multiply(int x, int res[], int res_size) 
    { 
        int carry = 0; 
        for (int i = 0; i < res_size; i++) 
        { 
            int prod = res[i] * x + carry; 
            res[i] = prod % 10; 
            carry = prod/10; 
        } 
        while (carry!=0) 
        { 
            res[res_size] = carry % 10; 
            carry = carry / 10; 
            res_size++; 
        } 
        return res_size; 
    } 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader s = new FastReader();
		int t=s.nextInt();
		while(t>0){
			int n=s.nextInt();
			int m=s.nextInt();
			int ans=0;
			if(m==0){
				System.out.println(0);
			}else if(n==m){
				fact(n);
			}
			else{
				int interval=0;
				if((m==1)||(m==n-1)){
					interval=n/2+1;
				}
				else{
					interval=n/m;
					
				}
				for(int i=0;i<=n-interval;i++){
					for(int j=i+interval-1;j<n;j++){
						ans++;
					}
				}
				ans+=m;
				System.out.println(ans);
			}
			t--;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	}

}