#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long int solve(int n, int m) { if (m == 0) { return 0; } m = min(m, n / 2); long long int sub = (long long int) (3 + 3 + 4 * (m - 1)) * m / 2; long long int add = (long long int) 2 * n * m; return add - sub; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; cout << solve(n, m) << "\n"; } }