#include <bits/stdc++.h>
using namespace std;
int lzy;
int n, m, r, c;
int ans;
int main() {
  cin >> lzy;
  while (lzy--) {
    cin >> n >> m >> r >> c;
    ans = 0;
    ans = max(ans, abs(1 - r) + abs(1 - c));
    ans = max(ans, abs(n - r) + abs(1 - c));
    ans = max(ans, abs(1 - r) + abs(m - c));
    ans = max(ans, abs(n - r) + abs(m - c));
    cout << ans << "\n";
  }
}
