#include #define clr(x) memset(x,0,sizeof(x)) #define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x)) #define clrmin(x) memset(x,-0x3f3f3f3f,sizeof(x)) #define pb push_back #define LL long long #define mod 1000000007 #define mp make_pair using namespace std; typedef pair pii; const int N = 1e5+10; const int M = 3e5+10; int T,n,m; int main(){ scanf("%d",&T); while(T --){ scanf("%d%d",&n,&m); int k = min(n / 2 ,m); LL ans = 1LL * (n - 2 * k + n - 1) * k; printf("%I64d\n",ans); } return 0; }