#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, q, s, t, c; cin >> n >> q >> s >> t >> c; s--; t--; auto f = [&](int i, int j) { if (i > j) j += n; return j - i; }; while (q--) { int u, v; cin >> u >> v; u--; v--; int ans = f(u, v); ans = min(ans, f(u, s) + f(t, v) + c); cout << ans << endl; } return 0; }