// Skyqwq #include #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long LL; template void chkMax(T &x, T y) { if (y > x) x = y; } template void chkMin(T &x, T y) { if (y < x) x = y; } template void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } int n, m, x1, x2; int main() { int T; read(T); while (T--) { read(n), read(m), read(x1), read(x2); int ans = min(x1 - 1, m - x2); if (x1 != x2) chkMin(ans, max((n - 1 + abs(x1 - x2) - 1) / 2, 0)); if (x1 == x2) chkMin(ans, (n - 1) / 2); chkMin(ans, n - 1); printf("%lld\n", 1ll * ans * ans); } return 0; }