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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAyoubsFunction solver = new CAyoubsFunction();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAyoubsFunction {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int q = sc.nextInt();
            while (q-- > 0) {
                long n = sc.nextLong(), m = sc.nextLong();
                if (m == 0) {
                    pw.println(0);
                    continue;
                }
                long ones = Math.min((n - 1) / 2, m);
                long ans = n * (n + 1) / 2;
                long sides = n - (2 * ones - 1);
                if (sides % 2 == 0) {
                    long temp = sides / 2;
                    long min = temp * (temp + 1);
                    ans -= min;
                } else {
                    long temp = (sides + 1) / 2;
                    long min = temp * (temp + 1) / 2;
                    ans -= min;
                    temp = sides / 2;
                    min = temp * (temp + 1) / 2;
                    ans -= min;
                }
                ans -= ones - 1;
                ans += m - ones;
                pw.println(ans);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

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

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

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

    }
}

