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

import static java.lang.Math.min;

public class C1301 {
    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;
        }
    }
    public static void main(String[] __) {
        PrintWriter out = new PrintWriter(System.out);
        FastReader sc = new FastReader();
        int tc = sc.nextInt();
        while (tc-- > 0) {
            long n = sc.nextLong(), m = sc.nextLong();
            if (m >= n) out.println((n * (n + 1))/2);
            else if (m == 0) out.println(0);
            else {
                long start = 1;
                long end = n;
                long mid = (start + end) / 2;
                while (end >= start) {
                    mid = (start + end) / 2;
                    if (start == end) break;
                    if (poss(n, m, mid)) end = mid;
                    else start = mid + 1;
                }
                long ans = (((n - mid + 1) * (n - mid + 2)) / 2);
                for (int i = 1; i < mid; i++) ans += min(i, n - i + 1) * m;
                out.println(ans);
            }
        }
    }

    private static boolean poss(long n, long m, long mid) {
        return m >= (n / mid);
    }
}
