#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #ifdef Doludu template ostream& operator << (ostream &o, vector vec) { o << "{"; int f = 0; for (T i : vec) o << (f++ ? " " : "") << i; return o << "}"; } void bug__(int c, auto ...a) { cerr << "\e[1;" << c << "m"; (..., (cerr << a << " ")); cerr << "\e[0m" << endl; } #define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x) #define bug(x...) bug_(32, x) #define bugv(x...) bug_(36, vector(x)) #define safe bug_(33, "safe") #else #define bug(x...) void(0) #define bugv(x...) void(0) #define safe void(0) #endif const int mod = 998244353, N = 300005; void solve() { auto good = [&](int x1, int y1, int x2, int y2) { return x1 == x2 || y1 == y2 || x1 + y1 == x2 + y2 || x1 - y1 == x2 - y2; }; int n, m, x1, y1, x2, y2; cin >> n >> m >> x1 >> y1 >> x2 >> y2, --x1, --y1, --x2, --y2; ll base = 2ll * n * m - 2; base -= m - 1; base -= n - 1; { int l = 0, r = n - 1; l = max(l, x1 + y1 - (m - 1)); r = min(r, x1 + y1); base -= r - l; } { int l = 0, r = n - 1; l = max(l, x1 - y1); r = min(r, x1 - y1 + m - 1); base -= r - l; } if (!good(x1, y1, x2, y2)) { cout << base - 2 << "\n"; return; } else if (x1 + y1 == x2 + y2) { base--; if (x1 < x2) { int more = min(y2, n - 1 - x2); base += more; } else { int more = min(x2, m - 1 - y2); base += more; } cout << base << "\n"; return; } else if (x1 - y1 == x2 - y2) { base--; if (x1 < x2) { int more = min(m - 1 - y2, n - 1 - x2); base += more; } else { int more = min(x2, y2); base += more; } cout << base << "\n"; return; } if (y1 == y2) { swap(n, m), swap(x1, y1), swap(x2, y2); } // x1 == x2 if (y1 > y2) { y1 = m - 1 - y1; y2 = m - 1 - y2; } base--; bug(x1, y1, x2, y2, n, m); // y1 < y2 int l = y2 - y1 + 1, r = m - 1 - y1; // [l, r] int up = max(x1, n - x1 - 1); // 2, 4, ..., 2up // 1, 2, ..., up auto f = [&](int x) { return min(x, up) + min(x / 2, up) - min(x / 2, up / 2); }; int tot = r - l + 1; int two = f(r) - f(l - 1); bug(tot, two); base += two; base += 2 * (tot - two); cout << base << "\n"; } int main() { ios::sync_with_stdio(false), cin.tie(0); int t = 1; cin >> t; while (t--) { solve(); } }