#include <bits/stdc++.h>
using namespace std;
int main() {
  (ios_base::sync_with_stdio(false), cin.tie(NULL));
  ;
  long long t, n, m, r, c;
  cin >> t;
  while (t--) {
    cin >> n >> m >> r >> c;
    long long dis = 0;
    dis = max(dis, (r - 1) + (c - 1));
    dis = max(dis, ((n - r) + (c - 1)));
    dis = max(dis, ((r - 1) + (m - c)));
    dis = max(dis, (n - r) + (m - c));
    cout << dis << endl;
  }
  return 0;
}
