#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll x, y;
int t;
cin >> t;
ll sol[t];
for (int i=0; i<t; i++) {
cin >> y >> x;
if (x >= y) {
sol[i] = (((x%2 == 1) ? (x*x + (1-y)) : ((x-1)*(x-1) + y)));
} else {
sol[i] = (((y%2 == 0) ? (y*y - (x-1)) : ((y-1)*(y-1) + x)));
}
}
for (int i=0; i<t; i++) {
cout << sol[i] << '\n';
}
return 0;
}