#include #include int main(){ int test; scanf("%d", &test); for(;test > 0; test--){ int n, m; scanf("%d%d", &n, &m); if(n == 1){ printf("0\n"); continue; } if(m > n/2) m = n/2; long long res = (long long)(n-1+n-(m*2))*(long long)(2*m)/(long long)2; printf("%lld\n", res); } return 0; }