N, Q, S, T, C = map(int, input().split()) S, T = S - 1, T - 1 for _ in range(Q): U, V = map(int, input().split()) U, V = U - 1, V - 1 ans = min((V - U) % N, (S - U) % N + C + (V - T) % N) print(ans)