#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int i,j;
cin>>i>>j;
if(i > j)
{
if(i%2 == 0)
{
cout<<(i-1)*(i-1) + (i-j)+i<<endl;
}
else
{
cout<<(i-1)*(i-1)+j<<endl;
}
}
else
{
if(j%2 == 0)
{
cout<<(j-1)*(j-1)+i<<endl;
}
else
{
cout<<(j-1)*(j-1)+(j-i)+j<<endl;
}
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkKCWludCB0OwoJY2luPj50OwoJCgkKCXdoaWxlKHQtLSkKCXsKCQlpbnQgaSxqOwoJCWNpbj4+aT4+ajsKCQkKCQlpZihpID4gaikKCQl7CgkJCWlmKGklMiA9PSAwKQoJCQl7CgkJCQljb3V0PDwoaS0xKSooaS0xKSArIChpLWopK2k8PGVuZGw7CgkJCX0KCQkJZWxzZQoJCQl7CgkJCQljb3V0PDwoaS0xKSooaS0xKStqPDxlbmRsOwoJCQl9CgkJfQoJCWVsc2UKCQl7CgkJCWlmKGolMiA9PSAwKQoJCQl7CgkJCQljb3V0PDwoai0xKSooai0xKStpPDxlbmRsOwoJCQl9CgkJCWVsc2UKCQkJewoJCQkJY291dDw8KGotMSkqKGotMSkrKGotaSkrajw8ZW5kbDsKCQkJfQoJCX0KCQkKCQkKCQkKCX0KCQoJCglyZXR1cm4gMDsKfQ==