#include #include #include #include #include #include #include using namespace std; typedef long long ll; const int maxn = 1e6 + 7; ll T,n,m; ll ans; int main(){ scanf("%lld",&T); while(T--){ scanf("%lld%lld",&n,&m); if(m>=n/2) ans=(1+n-1)*(n-1)/2; else ans=(n-1+n-1-2*m+1)*(2*m)/2; printf ("%lld\n",ans); } }