#include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef long long ll; const int maxn = 2e6 + 7; int T; int n , m , x1 , x2; int main() { scanf("%d",&T); while(T--){ scanf("%d%d%d%d",&n,&m,&x1,&x2); ll ans = min(x1 - 1 , m - x2); if(x1 > x2) swap(x1 , x2); int d = x2 - x1; ll l = 0 , r = n , mid; while(l <= r){ mid = (l + r) / 2; ll x1 = 1 + mid; ll x2 = max(mid - d + 2 , 0ll); if(d == 0){ x2 = max(mid - d + 1 , 0ll); } if(x1 + x2 >= n){ ans = min(ans , mid); r = mid - 1; } else l = mid + 1; } printf ("%lld\n",ans * ans); } return 0; }