#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, q, w, k;
  cin >> n >> h >> q >> w >> k;
  while (k--) {
    long long a, b, x, y;
    long long d = 0;
    cin >> a >> b >> x >> y;
    swap(a, b);
    swap(x, y);
    if (b == y) {
      cout << abs(a - x) << endl;
    } else {
      if ((a >= q) && (a <= w)) {
        d += abs(b - y);
        d += abs(a - x);
        cout << d << endl;
      } else {
        d += min(abs(a - q), abs(a - w));
        if (abs(a - q) <= abs(a - w)) {
          d += abs(q - x);
        } else {
          d += abs(w - x);
        }
        d += abs(b - y);
        cout << d << endl;
      }
    }
  }
  return 0;
}
