J=lambda:map(int,input().split()) N,Q,S,T,C=J() for q in[0]*Q:U,V=J();print(min((V-U)%N,(S-U)%N+C+(V-T)%N))