#include using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, a, b) for(int i = (a); i < (b); i++) #define per(i, a, b) for(int i = (b) - 1; i >= (a); --i) #define de(x) cout << #x << " = " << x << endl #define dd(x) cout << #x << " = " << x << " " #define endl '\n' #define pw(x) (1ll<<(x)) #define all(x) x.begin(), x.end() #define sz(x) (int)x. size() typedef long long ll; typedef double db; typedef pair pii; typedef vector vi; int t; int n,m; ll cal(ll t) { return (1+t)*t/2; } int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); while(cin>>t) { while(t--) { cin>>n>>m; ll ans=0; ll t=min(m,n/2); ans+=2*n*t-cal(t)*4+t; cout<