#include #include #include #define LL long long #define inf 0x3f const int mod = 1e9+7; using namespace std; int n,m; int main() { int t; cin >> t; while(t--){ int k,i,j; cin >> n >> m; if(m == 0){ cout << 0 << endl; continue; } k = min(m,n); if(k > n / 2) k = n / 2; i = 1,j = n; LL ans = 0; ans += 1LL*2 * n * k - 1LL*(1+2*k)*k; cout << ans << endl; } return 0; }