/** * author: mackerel38 * created: 11.07.2026 22:22:26 **/ #line 2 "library/utility/template.hpp" #include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using i128 = __int128; using u128 = unsigned __int128; using ld = long double; using str = string; using vi = vector; using vvi = vector>; using vvvi = vector>>; using pi = pair; using ppi = pair>; using pppi = pair>>; using vpi = vector>; using vvpi = vector>>; using vvvpi = vector>>>; using vll = vector; using vvll = vector>; using vvvll = vector>>; using pll = pair; using ppll = pair>; using pppll = pair>>; using vpll = vector>; using vvpll = vector>>; using vvvpll = vector>>>; template using pairs = pair; template using vec = vector; template using vvec = vec>; template using vvvec = vec>>; template using pq = priority_queue; template using pqg = priority_queue, greater>; #define vv(type, name, x, y, ...) vector> name((x), vector((y), ##__VA_ARGS__)) #define vvv(type, name, x, y, z, ...) vector>> name((x), vector>((y), vector((z), ##__VA_ARGS__))) #define rep_1(n) for (long long _=0LL; _<(long long)(n); ++_) #define rep_2(i, n) for (long long i=0LL; i<(long long)(n); ++i) #define rep_3(i, l, r) for (long long i=(long long)(l); i<(long long)(r); ++i) #define rep_4(i, l, r, s) for (long long i=(long long)(l); i<(long long)(r); i+=(long long)(s)) #define overload_rep(a, b, c, d, e, ...) e #define rep(...) overload_rep(__VA_ARGS__, rep_4, rep_3, rep_2, rep_1)(__VA_ARGS__) #define rep1_1(n) for (long long _=1LL; _<=(long long)(n); ++_) #define rep1_2(i, n) for (long long i=1LL; i<=(long long)(n); ++i) #define rep1_3(i, l, r) for (long long i=(long long)(l)+1LL; i<=(long long)(r); ++i) #define rep1_4(i, l, r, s) for (long long i=(long long)(l)+1LL; i<=(long long)(r); i+=(long long)(s)) #define overload_rep1(a, b, c, d, e, ...) e #define rep1(...) overload_rep1(__VA_ARGS__, rep1_4, rep1_3, rep1_2, rep1_1)(__VA_ARGS__) #define per_1(n) for (long long _=(long long)(n)-1LL; 0LL<=_; --_) #define per_2(i, n) for (long long i=(long long)(n)-1LL; 0LL<=i; --i) #define per_3(i, l, r) for (long long i=(long long)(r)-1LL; (long long)(l)<=i; --i) #define per_4(i, l, r, s) for (long long i=(long long)(r)-1LL; (long long)(l)<=i; i-=(long long)(s)) #define overload_per(a, b, c, d, e, ...) e #define per(...) overload_per(__VA_ARGS__, per_4, per_3, per_2, per_1)(__VA_ARGS__) #define per1_1(n) for (long long _=(long long)(n); 0LL<_; --_) #define per1_2(i, n) for (long long i=(long long)(n); 0LL>(i))&1) #define nextp(v) next_permutation((v).begin(), (v).end()) template bool next_combination(T l, T r, int k) { T m = l + k; if (l==r || r==m || m==l) return false; T t = m; while (l != t) { t--; if (*t < *(r-1)) { T d = m; while (*d <=*t) d++; iter_swap(t, d); rotate(t+1, d+1, r); rotate(m, m+(r-d)-1, r); return true; } } rotate(l, m, r); return false; } #define nextc(v, k) next_combination((v).begin(), (v).end(), k) #define Yes cout << "Yes\n" #define No cout << "No\n" #define YN(x) cout << ((x) ? "Yes\n" : "No\n") #define O(x) cout << (x) << '\n' #define ismid_1(x) true template bool inner_ismid_2(T x, U r) { return T{}<=x && x bool inner_ismid_3(T l, U x, V r) { return l<=x && x bool next_subset(T x, T& s) { if (s == T{}) return false; s = (s-1) & x; return true; } template constexpr vector enum_pow(T x, int n) { vector re(n+1); re[0] = T{1}; for (int i=1; i<=n; ++i) re[i] = re[i-1] * x; return re; } template inline T Pow(T x, U n) { T re = T{1}; if (n < U{}) { x = T{1} / x; n = -n; } while (U{} < n) { if ((n & U{1}) == 1) re *= x; x *= x; n >>= 1; } return re; } template inline bool chmin(T& x, U y) { if (x <= y) return false; x = y; return true; } template inline bool chmax(T& x, U y) { if (y <= x) return false; x = y; return true; } template auto Min(T x, U y) { using R = common_type_t; R a = x, b = y; return (b < a) ? b : a; } template auto Min(T x, U y, Args... args) { return Min(Min(x, y), args...); } template T Min(initializer_list v) { assert(v.size()); return *min_element(v.begin(), v.end()); } template auto Max(T x, U y) { using R = common_type_t; R a = x, b = y; return (a < b) ? b : a; } template auto Max(T x, U y, Args... args) { return Max(Max(x, y), args...); } template T Max(initializer_list v) { assert(v.size()); return *max_element(v.begin(), v.end()); } template struct is_string : false_type {}; template struct is_string> : true_type {}; template struct is_iterable : false_type {}; template struct is_iterable())), decltype(end(declval()))>> : conditional_t::value, false_type, true_type> {}; template::value, nullptr_t> = nullptr> auto Min(const T& x) { return x; } template::value, nullptr_t> = nullptr> auto Max(const T& x) { return x; } template::value, nullptr_t> = nullptr> auto Sum(const T& x) { return x; } template auto Min(const pair& p) { using R1 = decay_t; using R2 = decay_t; using R = decay_t>; R a = Min(p.first); R b = Min(p.second); return (b < a) ? b : a; } template auto Max(const pair& p) { using R1 = decay_t; using R2 = decay_t; using R = decay_t>; R a = Max(p.first); R b = Max(p.second); return (a < b) ? b : a; } template auto Sum(const pair& p) { using R1 = decay_t; using R2 = decay_t; using R = decay_t>; R res{}; res += Sum(p.first); res += Sum(p.second); return res; } template::value, nullptr_t> = nullptr> auto Min(const C& v) { assert(!v.empty()); auto it = v.begin(); auto re = Min(*it); for (++it; it!=v.end(); ++it) { auto v = Min(*it); if (v < re) re = v; } return re; } template::value, nullptr_t> = nullptr> auto Max(const C& v) { assert(!v.empty()); auto it = v.begin(); auto re = Max(*it); for (++it; it != v.end(); ++it) { auto v = Max(*it); if (re < v) re = v; } return re; } template::value, nullptr_t> = nullptr> auto Sum(const C& v) { using R = decay_t; R re = R{}; for (auto it=v.begin(); it!=v.end(); ++it) re += Sum(*it); return re; } template istream& operator>>(istream& s, pair& p) { s >> p.first >> p.second; return s; } template ostream& operator<<(ostream& s, const pair& p) { return s << p.first << ' ' << p.second; } template istream& operator>>(istream& s, vector& v) { for (auto& i : v) s >> i; return s; } template ostream& operator<<(ostream& s, const vector& v) { for (int i=0; i void debug_out(const T& x, const Args&... args) { cerr << x; if constexpr (sizeof...(args)) cerr << ' '; debug_out(args...); } #endif const vector dxy = {0, 1, 0, -1, 0}; const vector dx = {0, 1, 0, -1, 1, 1, -1, -1}; const vector dy = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr char nl = '\n'; constexpr char sp = ' '; constexpr int INF = numeric_limits::max()/2; constexpr long long LINF = numeric_limits::max()/2; template constexpr T infty = numeric_limits::is_integer ? (numeric_limits::max()/2) : numeric_limits::infinity(); constexpr long double eps = 1e-9; const long double PI = acos(-1); constexpr long long mod = 998244353; constexpr long long MOD = 1000000007; inline void IO() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } void solve(); #line 2 "contests/yukicoder590/g/main.cpp" int main() { IO(); int T=1; cin >> T; while (T--) solve(); } template bool isvalid(T x1, T y1, T x2, T y2) { return x1==x2 || y1==y2 || abs(x1-x2)==abs(y1-y2); } void solve() { ll H, W, h, w, x, y; cin >> H >> W >> h >> w >> x >> y; h--; w--; x--; y--; ll ans; { ll one = H+W; one += min(h, w); one += min(h, W-1-w); one += min(H-1-h, w); one += min(H-1-h, W-1-w); ans = 2*H*W - one; ans--; } if (isvalid(h, w, x, y)) { if (abs(h-x) == abs(w-y)) { if (x < h) { h = H-1-h; x = H-1-x; } if (y < w) { w = W-1-w; y = W-1-y; } ans -= x-h; ans += min(H-1-h, W-1-w); } else { if (y == w) { swap(H, W); swap(h, w); swap(x, y); } if (y < w) { w = W-1-w; y = W-1-y; } ans -= y-w; ans += W-1-w; { ll three = 0; three += (W-1-w+1)/2 - min(W-1-w, (max(y-w, max(h, H-1-h)))+1)/2; three += (W-1-w)/2 - min(W-1-w, max(y-w, 2*(max(h, H-1-h))))/2; ans += three; } } } else ans--; cout << ans << nl; }