#include #include #include #include #include using namespace std; const int maxn = 200; long long n,m; int main() { int T; scanf("%d",&T); while(T--){ scanf("%lld%lld",&n,&m); //if (n&1) n--; m = min( m , n/2 ); printf("%lld\n",2*n*m - m*(2*m+1) ); } return 0; }