#include #define LL long long using namespace std;bool h1; LL T,n,m,t,ans; bool h2;int main(){ cin>>T; while(T--){ scanf("%lld%lld",&n,&m),m=min(m,n/2); t=n-1,ans=0; printf("%lld\n",2ll*m*n-2ll*m*m-m); } return 0; }