#include using namespace std; #define Int register int #define int long long #define MAXN 105 template inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;} template inline void read (T &t,Args&... args){read (t);read (args...);} template inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');} int t,n,m; signed main(){ read (t); while (t --){ read (n,m); if (m * 2 >= n) write (n * (n - 1) / 2),putchar ('\n'); else write (max (0ll,2 * n * m - m * (4 * m + 2) / 2)),putchar ('\n'); } return 0; }