#include #define For(i,l,r) for (register int i=l; i<=r; i++) using namespace std; typedef unsigned long long LL; typedef signed long long ll; template inline void read(T &x) { char c = getchar(); int w = 1; x = 0; while (!isdigit(c)) (c == '-') && (w = -w), c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar(); x *= w; } int T; signed main() { read(T); while (T -- > 0) { ll n, m, x1, x2; read(n); read(m); read(x1); read(x2); if (n == 1 || m == 1) { puts("0"); continue; } ll step = min(n-1, min(x1-1, m-x2)); if (x1 == x2) { step = min(step, (n+1)/2-1); } else step = min(step, (n+abs(x1-x2))/2-1); // int q = n+abs(x1-x2); step = min(step, max(x1-2, x2-1 + n-2)); step = min(step, max(m-1-x2, m-x1 + n-2)); if (step < 0) step = 0; printf("%lld\n", step * step); } getchar(); return 0; }