You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room.

The building consists of n towers, h floors each, where the towers are labeled from 1 to n, the floors are labeled from 1 to h. There is a passage between any two adjacent towers (two towers i and i + 1 for all i: 1 ≤ i ≤ n - 1) on every floor x, where a ≤ x ≤ b. It takes exactly one minute to walk between any two adjacent floors of a tower, as well as between any two adjacent towers, provided that there is a passage on that floor. It is not permitted to leave the building.

 [Image]

The picture illustrates the first example. 

You have given k pairs of locations (t_{a}, f_{a}), (t_{b}, f_{b}): floor f_{a} of tower t_{a} and floor f_{b} of tower t_{b}. For each pair you need to determine the minimum walking time between these locations.


-----Input-----

The first line of the input contains following integers:

  n: the number of towers in the building (1 ≤ n ≤ 10^8),  h: the number of floors in each tower (1 ≤ h ≤ 10^8),  a and b: the lowest and highest floor where it's possible to move between adjacent towers (1 ≤ a ≤ b ≤ h),  k: total number of queries (1 ≤ k ≤ 10^4). 

Next k lines contain description of the queries. Each description consists of four integers t_{a}, f_{a}, t_{b}, f_{b} (1 ≤ t_{a}, t_{b} ≤ n, 1 ≤ f_{a}, f_{b} ≤ h). This corresponds to a query to find the minimum travel time between f_{a}-th floor of the t_{a}-th tower and f_{b}-th floor of the t_{b}-th tower.


-----Output-----

For each query print a single integer: the minimum walking time between the locations in minutes.


-----Example-----
Input
3 6 2 3 3
1 2 1 3
1 4 3 4
1 2 2 3

Output
1
4
2

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
(n, h, a, b, k) = list(map(int, input().strip().split()))
for i in range(k):
	(t1, f1, t2, f2) = list(map(int, input().strip().split()))
	if t1 == t2:
		print(abs(f1 - f2))
		continue
	else:
		e = abs(t1 - t2)
		if f1 >= a and f1 <= b:
			print(e + abs(f1 - f2))
		elif f1 < a:
			print(e + a - f1 + abs(a - f2))
		else:
			print(e + f1 - b + abs(b - f2))


(n, h, a, b, k) = list(map(int, input().split()))
for i in range(k):
	(ta, fa, tb, fb) = list(map(int, input().split()))
	s = abs(ta - tb)
	if (fa < a or fa > b) and ta != tb:
		s += min(abs(fa - a), abs(fa - b))
		if abs(fa - a) < abs(fa - b):
			e = a
		else:
			e = b
		s += abs(fb - e)
	else:
		s += abs(fa - fb)
	print(s)


__author__ = 'Esfandiar'
(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	res = 0
	if ta == tb:
		print(abs(fa - fb))
	else:
		res = abs(ta - tb)
		if fa < a:
			res += a - fa
			fa = a
		elif fa > b:
			res += fa - b
			fa = b
		res += abs(fa - fb)
		print(res)


def move(ct, cf, dt, df):
	global a, b
	if ct == dt:
		if cf == df:
			return (ct, cf, 0)
		else:
			move = df - cf
			cf = df
	elif cf >= a and cf <= b:
		move = dt - ct
		ct = dt
	elif cf < a:
		move = a - cf
		cf = a
	elif cf > b:
		move = b - cf
		cf = b
	return (ct, cf, abs(move))
(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	counter = 0
	(ta, fa, tb, fb) = map(int, input().split())
	while True:
		(ta, fa, nm) = move(ta, fa, tb, fb)
		counter += nm
		if nm == 0:
			break
	print(counter)


def readNums(type=int):
	return list(map(type, input().split()))
(n, h, a, b, k) = readNums()
for _ in range(k):
	(ta, fa, tb, fb) = readNums()
	if ta == tb:
		print(abs(fa - fb))
	else:
		res = abs(tb - ta)
		if fa > b:
			print(fa - b + res + abs(fb - b))
		elif fa < a:
			print(a - fa + res + abs(fb - a))
		else:
			print(res + abs(fa - fb))


(n, h, a, b, k) = [int(i) for i in input().split()]

def f(ta, fa, tb, fb, a, b):
	if ta == tb:
		return abs(fb - fa)
	l = [abs(fa - a) + abs(fb - a) + abs(ta - tb), abs(fa - b) + abs(fb - b) + abs(ta - tb)]
	if fa >= a and fa <= b:
		l += [abs(ta - tb) + abs(fb - fa)]
	return min(l)
for i in range(k):
	(ta, tb, fa, fb) = [int(j) for j in input().split()]
	print(f(ta, tb, fa, fb, a, b))


(n, h, a, b, k) = list(map(int, input().split()))

def ans(t1, f1, t2, f2):
	res = abs(t2 - t1)
	if res == 0:
		res += abs(f2 - f1)
	else:
		ff = -1
		if f1 > b:
			res += f1 - b
			ff = b
		elif f1 < a:
			res += a - f1
			ff = a
		else:
			ff = f1
		res += abs(ff - f2)
	return res
for i in range(k):
	(t1, f1, t2, f2) = list(map(int, input().split()))
	print(ans(t1, f1, t2, f2))


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fb - fa))
		continue
	if a <= fa <= b:
		f = fa
	elif abs(fa - a) + abs(fb - a) < abs(fa - b) + abs(fb - b):
		f = a
	else:
		f = b
	print(abs(tb - ta) + abs(fb - f) + abs(fa - f))


(n, h, a, b, k) = map(int, input().split())
ta = [0] * k
tb = [0] * k
fa = [0] * k
fb = [0] * k
for i in range(k):
	(ta[i], fa[i], tb[i], fb[i]) = map(int, input().split())
for i in range(k):
	s = abs(ta[i] - tb[i]) + abs(fa[i] - fb[i])
	if ta[i] != tb[i]:
		if fa[i] > b and fb[i] > b:
			s += min(fa[i] - b, fb[i] - b) * 2
		if fa[i] < a and fb[i] < a:
			s += min(a - fa[i], a - fb[i]) * 2
	print(s)


def main():
	(n, h, a, b, k) = [int(x) for x in input().split()]
	for _ in range(k):
		(ta, fa, tb, fb) = [int(x) for x in input().split()]
		if ta == tb:
			print(abs(fa - fb))
			continue
		sum = 0
		if not a <= fa <= b:
			if fa < a:
				sum += a - fa
				sum += abs(a - fb)
			else:
				sum += fa - b
				sum += abs(b - fb)
		else:
			sum = abs(fa - fb)
		print(abs(ta - tb) + sum)
main()


x = input()
x = x.split(' ')
n = int(x[0])
h = int(x[1])
a = int(x[2])
b = int(x[3])
k = int(x[4])
time = []
for i in range(0, k):
	t = 0
	z = input()
	z = z.split(' ')
	t1 = int(z[0])
	f1 = int(z[1])
	t2 = int(z[2])
	f2 = int(z[3])
	if t1 != t2:
		if f1 > b:
			t += f1 - b
			f1 = b
		elif f1 < a:
			t += a - f1
			f1 = a
		t += abs(f2 - f1)
		t += abs(t2 - t1)
	else:
		t += abs(f2 - f1)
	time.append(t)
for j in range(0, k):
	print(time[j])


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	counter = 0
	flag = -1
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 != t2:
		if f1 >= a and f1 <= b:
			counter += abs(t1 - t2)
			counter += abs(f1 - f2)
		elif f1 > b:
			counter += f1 - b
			counter += abs(t2 - t1)
			counter += abs(b - f2)
		else:
			counter += a - f1
			counter += abs(t2 - t1)
			counter += abs(a - f2)
	else:
		counter = abs(f1 - f2)
	print(counter)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	ans = abs(ta - tb)
	if ta == tb:
		ans += abs(fa - fb)
	br = fa
	if ta != tb and (not (a <= fa and fa <= b)):
		ans += min(abs(a - fa), abs(b - fa))
		if min(abs(a - fa), abs(b - fa)) == abs(a - fa):
			br = a
		else:
			br = b
	if ta != tb:
		ans += abs(br - fb)
	print(ans)


(n, h, a, b, k) = list(map(int, input().split()))
for _ in range(k):
	(t1, f1, t2, f2) = list(map(int, input().split()))
	if t1 == t2:
		print(abs(f2 - f1))
	elif (f1 < a or f1 > b) and (f2 < a or f2 > b):
		print(abs(t1 - t2) + min(abs(f1 - a) + abs(f2 - a), abs(f1 - b) + abs(f2 - b)))
	else:
		print(abs(t1 - t2) + abs(f1 - f2))


(n, h, a, b, k) = [int(i) for i in input().split()]
for i in range(k):
	(t1, f1, t2, f2) = [int(i) for i in input().split()]
	if t1 != t2:
		if f1 <= b and f1 >= a:
			z = 0
			curr = f1
		elif f2 <= b and f2 >= a:
			z = abs(f1 - f2)
			curr = f2
		elif abs(a - f1) > abs(b - f1):
			z = abs(b - f1)
			curr = b
		else:
			z = abs(a - f1)
			curr = a
		z = z + abs(t2 - t1) + abs(curr - f2)
		print(z)
	else:
		print(abs(f1 - f2))


def min_time(ta, fa, tb, fb):
	if ta == tb:
		return abs(fa - fb)
	elif a <= fa <= b and a <= fb <= b:
		return abs(ta - tb) + abs(fa - fb)
	elif fa >= b and fb >= b:
		return fa - b + fb - b + abs(ta - tb)
	elif fa <= a and fb <= a:
		return a - fa + a - fb + abs(ta - tb)
	elif (fa < a or fa > b) and (fb < a or fb > b):
		return min(abs(fa - a), abs(fa - b)) + b - a + min(abs(fb - a), abs(fb - b)) + abs(ta - tb)
	elif a <= fa <= b and fb < a:
		return a - fb + abs(ta - tb) + fa - a
	elif a <= fa <= b and fb > b:
		return fb - b + abs(ta - tb) + b - fa
	elif a <= fb <= b and fa < a:
		return a - fa + abs(ta - tb) + fb - a
	elif a <= fb <= b and fa > b:
		return fa - b + abs(ta - tb) + b - fb
(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	print(min_time(ta, fa, tb, fb))


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(x, y, w, z) = map(int, input().split())
	if x == w:
		print(abs(y - z))
	elif a <= min(y, z) and max(y, z) <= b:
		print(abs(y - z) + abs(x - w))
	else:
		print(min(abs(y - a) + abs(z - a) + abs(x - w), abs(y - b) + abs(z - b) + abs(x - w)))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if fa > fb:
		(fa, fb) = (fb, fa)
	ans = abs(ta - tb) + abs(fa - fb)
	if ta != tb:
		if fa > b:
			ans += 2 * (fa - b)
		elif fb < a:
			ans += 2 * (a - fb)
	print(ans)


from collections import defaultdict
from math import sqrt, factorial, gcd, log2
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 9)
(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	ans = 0
	(ta, fa, tb, fb) = map(int, input().split())
	z1 = abs(ta - tb)
	if a <= fa <= b or z1 == 0:
		z2 = abs(fb - fa)
		print(z1 + z2)
	else:
		z2 = abs(fa - a) + abs(fb - a)
		z3 = abs(fa - b) + abs(fb - b)
		print(min(z2, z3) + z1)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 == t2:
		print(abs(f2 - f1))
	elif f1 < a:
		print(a - f1 + abs(t2 - t1) + abs(f2 - a))
	elif f1 > b:
		print(f1 - b + abs(t2 - t1) + abs(f2 - b))
	else:
		print(abs(f2 - f1) + abs(t2 - t1))


(n, h, a, b, k) = list(map(int, input().split()))
for i in range(k):
	(t1, f1, t2, f2) = list(map(int, input().split()))
	if t1 == t2:
		print(abs(f1 - f2))
		continue
	ans = abs(t1 - t2)
	p = 0
	if f1 < a:
		ans += a - f1
		p = a
	elif f1 > b:
		ans += f1 - b
		p = b
	else:
		p = f1
	ans += abs(p - f2)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
ans = 0
for i in range(k):
	(x1, y1, x2, y2) = map(int, input().split())
	ans = abs(x2 - x1)
	if ans == 0 or (a <= y1 and y1 <= b):
		ans += abs(y1 - y2)
	elif y1 > b:
		ans += abs(y1 - b) + abs(y2 - b)
	else:
		ans += abs(y1 - a) + abs(y2 - a)
	print(ans)


def main():
	(n, h, a, b, k) = map(int, input().split())
	for i in range(k):
		(ta, fa, tb, fb) = map(int, input().split())
		if ta == tb:
			print(abs(fa - fb))
		elif b < fa and b < fb:
			print(fa - b + fb - b + abs(ta - tb))
		elif fa < a and fb < a:
			print(a - fa + a - fb + abs(ta - tb))
		else:
			print(abs(fa - fb) + abs(ta - tb))
main()


(n, h, a, b, k) = list(map(int, input().split()))
for x in range(k):
	(ta, fa, tb, fb) = list(map(int, input().split()))
	if ta == tb:
		print(abs(fa - fb))
	elif fa >= a and fa <= b:
		taaa = abs(tb - ta)
		la = abs(fa - fb)
		print(la + taaa)
	elif fa < a:
		tam = abs(a - fa)
		taaa = abs(tb - ta)
		la = abs(a - fb)
		print(la + taaa + tam)
	else:
		tam = abs(fa - b)
		taaa = abs(tb - ta)
		la = abs(b - fb)
		print(la + taaa + tam)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(t_a, f_a, t_b, f_b) = map(int, input().split())
	buf = abs(t_b - t_a)
	if t_a == t_b:
		buf = abs(f_a - f_b)
	elif f_a > b:
		buf += f_a - b
		buf += abs(b - f_b)
	elif f_a < a:
		buf += a - f_a
		buf += abs(a - f_b)
	else:
		buf += abs(f_a - f_b)
	print(buf)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(bud1, piet1, bud2, piet2) = map(int, input().split())
	if bud1 == bud2:
		print(abs(piet2 - piet1))
	else:
		dystans = abs(bud1 - bud2)
		if piet1 >= b:
			print(dystans + abs(b - piet1) + abs(b - piet2))
		elif piet1 <= a:
			print(dystans + abs(a - piet1) + abs(a - piet2))
		else:
			print(dystans + abs(piet1 - piet2))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	answer = 0
	(ta, fa, tb, fb) = map(int, input().split())
	if ta != tb:
		if a <= fa <= b:
			answer += abs(tb - ta)
		else:
			answer += min(abs(fa - a), abs(fa - b)) + abs(tb - ta)
			if fa > b:
				fa = b
			elif fa < a:
				fa = a
	answer += abs(fa - fb)
	print(answer)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 == t2:
		ans = abs(f1 - f2)
	else:
		if f1 < a:
			d1 = a
		elif f1 in range(a, b + 1):
			d1 = f1
		else:
			d1 = b
		ans = abs(d1 - f1) + abs(t1 - t2) + abs(d1 - f2)
	print(ans)


def building(a, b, lst):
	z = list()
	for elem in lst:
		if elem[0] == elem[2]:
			z.append(abs(elem[1] - elem[3]))
		elif elem[1] < a and elem[3] < a:
			z.append(abs(elem[0] - elem[2]) + 2 * a - elem[1] - elem[3])
		elif elem[1] > b and elem[3] > b:
			z.append(abs(elem[0] - elem[2]) - 2 * b + elem[1] + elem[3])
		else:
			z.append(abs(elem[0] - elem[2]) + abs(elem[1] - elem[3]))
	return z
(N, H, A, B, Q) = [int(i) for i in input().split()]
m = list()
for i in range(Q):
	(ta, fa, tb, fb) = [int(j) for j in input().split()]
	m.append([ta, fa, tb, fb])
print(*building(A, B, m), sep='\n')


def get_tower_diff(a, b, f):
	if a <= f <= b:
		return (0, f)
	if abs(f - a) < abs(f - b):
		return (abs(f - a), a)
	return (abs(f - b), b)
(n, h, a, b, k) = tuple(map(int, input().split()))
while k:
	k -= 1
	(ta, fa, tb, fb) = tuple(map(int, input().split()))
	if ta != tb:
		(dt1, floor) = get_tower_diff(a, b, fa)
		print(abs(ta - tb) + abs(fa - floor) + abs(fb - floor))
	else:
		print(abs(fa - fb))


(n, h, a, b, k) = list(map(int, input().split()))
for i in range(k):
	(ta, fa, tb, fb) = list(map(int, input().split()))
	if ta != tb:
		c1 = a - fa if fa < a else fa - b if fa > b else 0
		fa = a if fa < a else b if fa > b else fa
	else:
		c1 = 0
	c2 = abs(ta - tb)
	c3 = abs(fa - fb)
	print(c1 + c2 + c3)


(n, h, a, b, k) = map(int, input().split())
l = 0
l1 = 0
for i in range(k):
	cnt = 0
	(fa, ta, fb, tb) = map(int, input().split())
	cnt += max(fa, fb) - min(fa, fb)
	if cnt == 0:
		cnt += max(ta, tb) - min(ta, tb)
	elif a <= ta <= b or a <= tb <= b:
		cnt += max(tb, ta) - min(tb, ta)
	else:
		l = a - min(ta, tb)
		l1 = max(ta, tb) - b
		if l > 0 and l1 > 0:
			cnt += max(tb, ta) - min(tb, ta)
		elif l > 0 and l1 < 0:
			cnt += l + a - max(tb, ta)
		elif l < 0 and l1 > 0:
			cnt += l1 + min(tb, ta) - b
	print(cnt)


(n, h, a, b, k) = list(map(int, input().split()))
for i in range(k):
	(ta, ha, tb, hb) = list(map(int, input().split()))
	m = 0
	if ta != tb:
		if ha < a and hb < a:
			m = a - ha + a - hb + abs(ta - tb)
		elif ha < a and hb >= a:
			m = hb - ha + abs(ta - tb)
		elif ha > b and hb > b:
			m = ha - b + hb - b + abs(ta - tb)
		elif ha > b and hb <= b:
			m = ha - hb + abs(ta - tb)
		else:
			m = abs(ha - hb) + abs(ta - tb)
	else:
		m = abs(ha - hb)
	print(m)


(n, h, a, b, k) = map(int, input().split())
(x, c) = ([], [])
f = 0
for i in range(k):
	x.append(list(map(int, input().split())))
for i in range(k):
	if x[i][0] == x[i][2]:
		c.append(abs(x[i][3] - x[i][1]))
	else:
		if x[i][1] > b:
			f += abs(x[i][1] - b) + abs(x[i][3] - b)
		elif x[i][1] < a:
			f += abs(x[i][1] - a) + abs(x[i][3] - a)
		elif x[i][1] >= a and x[i][1] <= b:
			f += abs(x[i][3] - x[i][1])
		c.append(abs(x[i][2] - x[i][0]) + f)
	f = 0
for i in range(k):
	print(c[i], end=' ')


(n, h, a, b, k) = [int(x) for x in input().split()]
for t in range(k):
	(ta, fa, tb, fb) = [int(x) for x in input().split()]
	if (fa < a and fb < a) and ta != tb:
		print(2 * a - fa - fb + abs(tb - ta))
	elif (fa > b and fb > b) and ta != tb:
		print(-2 * b + fa + fb + abs(tb - ta))
	else:
		print(abs(tb - ta) + abs(fb - fa))


R = lambda : map(int, input().split())
(n, h, a, b, k) = R()
for _ in [0] * k:
	(t, f, s, g) = R()
	print(abs(f - g) + (2 * max(0, min(f, g) - b) + 2 * max(0, a - max(f, g)) + abs(t - s)) * (t != s))


import itertools
import math
from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	(n, h, a, b, k) = input_ints()
	for tmp in range(k):
		(ta, fa, tb, fb) = input_ints()
		if ta == tb:
			ans = abs(fa - fb)
		else:
			ans = 0
			if fa < a:
				ans = a - fa
				fa = a
			elif fa > b:
				ans = fa - b
				fa = b
			ans += abs(ta - tb) + abs(fb - fa)
		print(ans)
solve()


(towers, floors, a, b, q) = map(int, input().split())
for i in range(q):
	ans = 0
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 == t2:
		print(abs(f1 - f2))
	else:
		ans += abs(t1 - t2)
		if f1 > b:
			ans += f1 - b
			f1 = b
		elif f1 < a:
			ans += a - f1
			f1 = a
		ans += abs(f1 - f2)
		print(ans)


import math
import sys
first_line = input()
first_line = first_line.split(' ')
a = int(first_line[2])
b = int(first_line[3])
for line in sys.stdin:
	line = line.split(' ')
	ta = int(line[0])
	fa = int(line[1])
	tb = int(line[2])
	fb = int(line[3])
	if ta == tb:
		print(int(math.fabs(fb - fa)))
		continue
	minutes = math.fabs(tb - ta)
	if b >= fa and fa >= a:
		minutes += math.fabs(fb - fa)
	elif fa > b:
		minutes += fa - b
		minutes += math.fabs(fb - b)
	elif a > fa:
		minutes += a - fa
		minutes += math.fabs(fb - a)
	print(int(minutes))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
(n, h, a, b, k) = mi()
for _ in range(k):
	(ta, fa, tb, fb) = mi()
	ans = 0
	if ta == tb:
		ans = abs(fa - fb)
	else:
		if a <= fa and fa <= b:
			pass
		elif fa < a:
			ans += a - fa
			fa = a
		else:
			ans += fa - b
			fa = b
		ans += abs(ta - tb) + abs(fa - fb)
	print(ans)


import sys
(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta - tb == 0:
		print(abs(fa - fb))
	else:
		if fa >= a and fa <= b:
			t = abs(ta - tb) + abs(fa - fa) + abs(fb - fa)
		elif fb >= a and fb <= b:
			t = abs(ta - tb) + abs(fa - fb) + abs(fb - fb)
		else:
			t1 = abs(ta - tb) + abs(fa - a) + abs(fb - a)
			t2 = abs(ta - tb) + abs(fa - b) + abs(fb - b)
			t = min(t1, t2)
		print(t)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	ans = abs(tb - ta)
	ia = 0
	ib = 0
	if fa >= a and fa <= b:
		ia = fa
	elif fa > b:
		ia = b
	else:
		ia = a
	if fb >= a and fb <= b:
		ib = fb
	elif fb > b:
		ib = b
	else:
		ib = a
	ans += abs(ia - ib) + abs(ia - fa) + abs(ib - fb)
	if ta != tb:
		print(ans)
	else:
		print(abs(fa - fb))


from sys import stdin as cin
from sys import stdout as cout

def main():
	(n, h, a, b, k) = map(int, cin.readline().split())
	for i in range(k):
		(ta, fa, tb, fb) = map(int, cin.readline().split())
		if ta == tb:
			print(abs(fa - fb))
		else:
			o = abs(ta - tb)
			if fa < a and fb < a:
				o += 2 * a - fa - fb
			elif fa > b and fb > b:
				o += fa + fb - 2 * b
			else:
				o += abs(fb - fa)
			print(o)
main()


def f(n, h, a, b, q):
	(ta, fa, tb, fb) = q
	if ta != tb:
		if fa >= a and fa <= b:
			return abs(fa - fb) + abs(ta - tb)
		if fa > b:
			return abs(fa - b) + abs(ta - tb) + abs(b - fb)
		else:
			return abs(a - fa) + abs(ta - tb) + abs(a - fb)
	else:
		return abs(fa - fb)
(n, h, a, b, k) = [int(i) for i in input().split()]
for _ in range(k):
	q = [int(i) for i in input().split()]
	print(f(n, h, a, b, q))


import math

def get_distance(t1, f1, t2, f2, a, b):
	if t1 == t2:
		return int(math.fabs(f2 - f1))
	d = int(math.fabs(t1 - t2))
	h = f1
	if f1 > b:
		d += f1 - b
		h = b
	elif f1 < a:
		d += a - f1
		h = a
	if f2 != h:
		d += int(math.fabs(f2 - h))
	return d
(n, h, a, b, k) = map(int, input().split())
for i in range(0, k):
	(t1, f1, t2, f2) = map(int, input().split())
	print(get_distance(t1, f1, t2, f2, a, b))


(n, h, a, b, k) = list(map(int, input().split()))
while k:
	k -= 1
	(t1, f1, t2, f2) = list(map(int, input().split()))
	if t1 == t2:
		print(abs(f2 - f1))
	elif (f1 < a or f1 > b) and (f2 < a or f2 > b):
		print(abs(t1 - t2) + min(abs(f1 - a) + abs(f2 - a), abs(f1 - b) + abs(f2 - b)))
	else:
		print(abs(t1 - t2) + abs(f1 - f2))


(n, h, a, b, k) = list(map(int, input().split()))
for i in range(k):
	(ta, fa, tb, fb) = list(map(int, input().split()))
	time = abs(tb - ta)
	if time:
		if fa < a:
			time += a - fa
			time += abs(a - fb)
		elif fa > b:
			time += fa - b
			time += abs(b - fb)
		else:
			time += abs(fa - fb)
	else:
		time += abs(fa - fb)
	print(time)


(n, h, a, b, k) = list(map(int, input().split()))

def dtopassages(fa, fb, a, b):
	if fa >= a and fb <= b:
		return abs(fa - fb)
	else:
		da = abs(fa - a) + abs(fb - a)
		db = abs(fa - b) + abs(fb - b)
		return min(da, db)
for _ in range(k):
	(ta, fa, tb, fb) = list(map(int, input().split()))
	if ta == tb:
		print(abs(fb - fa))
	else:
		print(dtopassages(fa, fb, a, b) + abs(ta - tb))


def build():
	(n, h, a, b, k) = map(int, input().split())
	L = []
	for i in range(k):
		L.append(list(map(int, input().split())))
	for i in range(k):
		if L[i][0] == L[i][2]:
			if L[i][3] > L[i][1]:
				print(L[i][3] - L[i][1])
			else:
				print(L[i][1] - L[i][3])
		elif L[i][1] > b:
			if L[i][3] > b:
				print(L[i][1] - b + abs(L[i][2] - L[i][0]) + (L[i][3] - b))
			else:
				print(L[i][1] - b + abs(L[i][2] - L[i][0]) + (b - L[i][3]))
		elif L[i][1] < a:
			if a > L[i][3]:
				print(a - L[i][1] + abs(L[i][2] - L[i][0]) + (a - L[i][3]))
			else:
				print(a - L[i][1] + abs(L[i][2] - L[i][0]) + (L[i][3] - a))
		elif L[i][1] > L[i][3]:
			print(abs(L[i][2] - L[i][0]) + (L[i][1] - L[i][3]))
		else:
			print(abs(L[i][2] - L[i][0]) + (L[i][3] - L[i][1]))
build()


(n, m, a, b, k) = map(int, input().split())
for i in range(k):
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == x2:
		print(abs(y1 - y2))
		continue
	if y1 >= b:
		print(y1 - b + abs(y2 - b) + abs(x1 - x2))
		continue
	elif y1 <= a:
		ans = abs(x1 - x2) + abs(y2 - a) + abs(y1 - a)
		print(ans)
		continue
	else:
		ans = abs(x1 - x2) + abs(y2 - y1)
		print(ans)
		continue


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	if f1 > b and t1 != t2:
		time = f1 - b
		start = b
	elif f1 < a and t1 != t2:
		time = a - f1
		start = a
	else:
		time = 0
		start = f1
	time += abs(t1 - t2) + abs(start - f2)
	print(time)


(n, h, a, b, k) = map(int, input().strip().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().strip().split())
	horizontal = abs(ta - tb)
	walking_floor = fa
	vertical = 0
	if horizontal == 0:
		vertical += abs(fa - fb)
	else:
		if fa >= b:
			vertical += abs(fa - b)
			fa = b
		elif fa <= a:
			vertical += abs(fa - a)
			fa = a
		vertical += abs(fa - fb)
	print(horizontal + vertical)


(n, h, a, b, k) = input().split()
(n, h, a, b, k) = (int(n), int(h), int(a), int(b), int(k))
for i in range(k):
	(ta, fa, tb, fb) = input().split()
	(ta, fa, tb, fb) = (int(ta), int(fa), int(tb), int(fb))
	(x, y) = (int(), int())
	if ta == tb:
		print(abs(fa - fb))
	else:
		if fa >= a and fa <= b:
			x = 0
			y = fa
		elif abs(fa - a) <= abs(fa - b):
			x = abs(fa - a)
			y = a
		else:
			x = abs(fa - b)
			y = b
		print(x + abs(ta - tb) + abs(fb - y))


(n, h, a, b, k) = map(int, input().split(' '))
for _ in range(k):
	(ax, ay, bx, by) = map(int, input().split(' '))
	if ax != bx:
		ans1 = abs(bx - ax)
		ans2 = ans1
		if ay < a or ay > b:
			tmp1 = abs(ay - a) + abs(by - a)
			tmp2 = abs(ay - b) + abs(by - b)
			ans1 += min(tmp1, tmp2)
		else:
			ans1 += abs(by - ay)
		if by < a or by > b:
			tmp1 = abs(ay - a) + abs(by - a)
			tmp2 = abs(ay - b) + abs(by - b)
			ans2 += min(tmp1, tmp2)
		else:
			ans2 += abs(by - ay)
		print(min(ans1, ans2))
	else:
		print(abs(ay - by))


(n, h, a, b, k) = map(int, input().split())
while k:
	k -= 1
	(ta, fa, tb, fb) = map(int, input().split())
	ans = 0
	if ta == tb:
		print(abs(fa - fb))
		continue
	if fa < a:
		ans += a - fa
		ans += abs(fb - a)
	elif fa > b:
		ans += fa - b
		ans += abs(fb - b)
	else:
		ans += abs(fa - fb)
	ans += abs(ta - tb)
	print(ans)


from sys import stdin, stdout
(n, h, a, b, k) = tuple(map(int, stdin.readline().split()))
tafatbfb = [tuple(map(int, line.split())) for line in stdin]
ans = []
for (ta, fa, tb, fb) in tafatbfb:
	cans = 0
	if ta != tb:
		cans += abs(ta - tb)
		if fa < a or fb < a:
			cans += abs(fa - a) + abs(fb - a)
		elif fa > b or fb > b:
			cans += abs(b - fa) + abs(b - fb)
		else:
			cans += abs(fa - fb)
	else:
		cans += abs(fa - fb)
	ans.append(str(cans))
stdout.write('\n'.join(ans))


def f(l):
	dist = lambda a, b: a - b if a > b else b - a
	global a, b
	(ta, fa, tb, fb) = l
	ht = dist(ta, tb)
	if fa >= a and fa <= b or (fb >= a and fb <= b) or ht == 0:
		return ht + dist(fa, fb)
	return ht + min(dist(fa, a) + dist(fb, a), dist(fa, b) + dist(fb, b))
(n, h, a, b, k) = list(map(int, input().split()))
[print(f(list(map(int, input().split())))) for _ in range(k)]


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
	else:
		s = 0
		ft = fa
		if fa < a:
			s = a - fa
			ft = a
		elif fa > b:
			s = fa - b
			ft = b
		print(s + abs(ta - tb) + abs(ft - fb))


[n, h, a, b, k] = [int(x) for x in input().split()]
case = []
for i in range(0, k):
	case.append([int(x) for x in input().split()])
for i in range(0, k):
	move = 0
	if case[i][0] == case[i][2]:
		move = abs(case[i][1] - case[i][3])
	else:
		move = abs(case[i][0] - case[i][2])
		if a <= case[i][1] <= b and a <= case[i][3] <= b:
			move = move + abs(case[i][1] - case[i][3])
		else:
			move = move + min(abs(a - case[i][1]) + abs(a - case[i][3]), abs(b - case[i][1]) + abs(b - case[i][3]))
	print(move)


(n, h, a, b, k) = map(int, input().split())
s = ''
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	c = abs(tb - ta)
	if c == 0:
		c += abs(fb - fa)
	elif not a <= fa <= b:
		c += min(abs(fa - a), abs(fa - b))
		if abs(fa - a) < abs(fa - b):
			c += abs(a - fb)
		else:
			c += abs(b - fb)
	else:
		c += abs(fb - fa)
	s += str(c) + '\n'
print(s)


s = list(map(int, input().split()))
(n, h, a, b, k) = (s[0], s[1], s[2], s[3], s[4])
for i in range(k):
	s = list(map(int, input().split()))
	(ta, fa, tb, fb) = (s[0], s[1], s[2], s[3])
	if ta == tb:
		print(abs(fa - fb))
	elif fa >= a and fa <= b or (fb >= a and fb <= b):
		print(abs(ta - tb) + abs(fa - fb))
	elif fa >= b:
		if fb >= b:
			print(abs(ta - tb) + (fa - b) + (fb - b))
		else:
			print(fa - fb + abs(ta - tb))
	elif fb >= b:
		print(fb - fa + abs(ta - tb))
	else:
		print(a - fa + a - fb + abs(ta - tb))


(n, h, a, b, q) = map(int, input().split())
for x in range(q):
	(ta, fa, tb, fb) = map(int, input().split())
	if fa <= b and fa >= a:
		print(abs(tb - ta) + abs(fb - fa))
	elif fa > b and fb <= b:
		print(abs(tb - ta) + fa - fb)
	elif fa > b and fb > b and (tb != ta):
		print(abs(tb - ta) + (fb - b) + (fa - b))
	elif fa > b and fb > b and (tb == ta):
		print(abs(tb - ta) + abs(fb - fa))
	elif fa < a and fb >= a:
		print(abs(tb - ta) + fb - fa)
	elif fa < a and fb < a and (tb != ta):
		print(abs(tb - ta) + (a - fb) + (a - fa))
	elif fa < a and fb < a and (tb == ta):
		print(abs(tb - ta) + abs(fb - fa))


(towers, floors, lowest, highest, k) = map(int, input().split())
for i in range(k):
	(x1, y1, x2, y2) = map(int, input().split())
	ans = 0
	if x1 == x2:
		ans = max(y1, y2) - min(y1, y2)
	else:
		ans += max(x1, x2) - min(x1, x2)
		if y1 > highest:
			ans += y1 - highest
			y1 = highest
		elif y1 < lowest:
			ans += lowest - y1
			y1 = lowest
		y2 = abs(y2 - y1)
		ans += y2
	print(ans)


import sys, collections
(n, h, a, b, k) = map(int, sys.stdin.readline().split())
for _ in range(k):
	(na, fa, nb, fb) = map(int, sys.stdin.readline().split())
	if na == nb:
		print(abs(fa - fb))
	elif a <= fa <= b:
		print(abs(na - nb) + abs(fa - fb))
	else:
		print(min(abs(fa - b) + abs(na - nb) + abs(b - fb), abs(fa - a) + abs(na - nb) + abs(a - fb)))


def getMinutes(ta, fa, tb, fb, a, b):
	vis = fa
	res = 0
	if ta == tb:
		res = abs(fa - fb)
	else:
		if fa < a:
			res = res + abs(fa - a)
			vis = a
		elif fa > b:
			res = res + abs(fa - b)
			vis = b
		res = res + abs(ta - tb)
		if vis != fb:
			res = res + abs(fb - vis)
	return res
(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	print(getMinutes(ta, fa, tb, fb, a, b))


(n, h, a, b, k) = [int(x) for x in input().split()]
for _ in range(k):
	(n1, h1, n2, h2) = [int(x) for x in input().split()]
	res = abs(n1 - n2)
	if a <= h1 <= b or a <= h2 <= b or res == 0:
		res += abs(h1 - h2)
	else:
		res += min([abs(h1 - x) + abs(h2 - x) for x in [a, b]])
	print(res)


(n, h, a, b, k) = map(int, input().split())
res = []
for i in range(k):
	count = 0
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		count += abs(fa - fb)
	elif fa < a:
		count += a - fa + abs(ta - tb) + abs(a - fb)
	elif fa > b:
		count += fa - b + abs(ta - tb) + abs(b - fb)
	else:
		count += abs(ta - tb) + abs(fa - fb)
	res.append(count)
print(*res, sep='\n')


(n, h, a, b, k) = map(int, input().split())
for q in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	cost_tower = abs(t1 - t2)
	if a < f1 < b or a < f1 < b or t1 == t2:
		cost_floor = abs(f2 - f1)
	else:
		cost_floor = min(abs(f1 - a) + abs(a - f2), abs(f1 - b) + abs(b - f2))
	print(cost_floor + cost_tower)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 == t2:
		print(abs(f1 - f2))
	else:
		ans = 0
		if f1 >= a and f1 <= b:
			ans += abs(t1 - t2)
			ans += abs(f1 - f2)
		else:
			k = min(abs(f1 - a), abs(f1 - b))
			ans += k
			ans += abs(t1 - t2)
			if abs(f1 - a) < abs(f1 - b):
				ans += abs(f2 - a)
			else:
				ans += abs(f2 - b)
		print(ans)


from sys import stdin
from collections import defaultdict
(n, h, a, b, k) = [int(x) for x in input().split()]
for i in range(k):
	(ta, fa, tb, fb) = [int(x) for x in input().split()]
	res = abs(tb - ta)
	if res == 0:
		res = abs(fa - fb)
	else:
		if fa < a:
			res += a - fa
			res += abs(a - fb)
		if fa > b:
			res += fa - b
			res += abs(b - fb)
		if a <= fa <= b:
			res += abs(fb - fa)
	print(res)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	d = 0
	if t1 != t2:
		if f1 < a:
			(d, f1) = (a - f1, a)
		elif f1 > b:
			(d, f1) = (f1 - b, b)
	print(d + abs(t1 - t2) + abs(f1 - f2))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(x, y, X, Y) = map(int, input().split())
	if x == X:
		ans = abs(y - Y)
	else:
		ans = abs(x - X)
		if y < a or y > b:
			if abs(y - a) < abs(y - b):
				c = a
			else:
				c = b
			ans += min(abs(y - a), abs(y - b))
			ans += abs(c - Y)
		else:
			ans += abs(y - Y)
	print(ans)


st = input()
st = st.split(' ')
n = int(st[0])
h = int(st[1])
a = int(st[2])
b = int(st[3])
k = int(st[4])
answ = []
for i in range(k):
	answer = 0
	st = input()
	st = st.split(' ')
	t1 = int(st[0])
	f1 = int(st[1])
	t2 = int(st[2])
	f2 = int(st[3])
	if t2 == t1:
		print(abs(f2 - f1))
		continue
	answer = abs(t2 - t1)
	if f1 >= a and f1 <= b:
		answer += abs(f2 - f1)
	if f1 < a:
		answer += abs(a - f1) + abs(a - f2)
	if f1 > b:
		answer += abs(b - f1) + abs(b - f2)
	print(answer, end='\n')


(pocBudov, pocPosch, minPohyb, maxPohyb, pocOtazok) = list(map(int, input().split()))
odpovede = []
for i in range(pocOtazok):
	otazka = list(map(int, input().split()))
	(od, do) = (otazka[:2], otazka[2:])
	if od[1] >= minPohyb and od[1] <= maxPohyb:
		odpovede.append(abs(do[0] - od[0]) + abs(do[1] - od[1]))
	elif od[0] == do[0]:
		odpovede.append(abs(od[1] - do[1]))
	else:
		if od[1] > maxPohyb:
			x = maxPohyb
		else:
			x = minPohyb
		odpovede.append(abs(do[0] - od[0]) + abs(min(maxPohyb - od[1], od[1] - minPohyb)) + abs(x - do[1]))
for i in odpovede:
	print(i)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	res = 0
	(t_a, f_a, t_b, f_b) = map(int, input().split())
	(t_1, t_2) = (f_a, f_b)
	if f_a < a:
		res += abs(f_a - a)
		t_1 = a
	elif f_a > b:
		res += abs(f_a - b)
		t_1 = b
	if f_b < a:
		res += abs(f_b - a)
		t_2 = a
	elif f_b > b:
		res += abs(f_b - b)
		t_2 = b
	res += abs(t_a - t_b) + abs(t_1 - t_2)
	if t_a == t_b:
		res = abs(f_a - f_b)
	print(res)


from sys import stdin

def main():
	(n, h, a, b, k) = map(int, input().split())
	l = stdin.read().splitlines()
	for (i, s) in enumerate(l):
		(x, y, u, v) = map(int, s.split())
		if y > v:
			(y, v) = (v, y)
		if x != u:
			x = abs(x - u) + v - y
			if b < y:
				x += (y - b) * 2
			elif v < a:
				x += (a - v) * 2
		else:
			x = v - y
		l[i] = str(x)
	print('\n'.join(l))
main()


(n, h, a, b, k) = map(lambda x: int(x), input().split(' '))

def min(a, b):
	return a if a < b else b
for i in range(k):
	(x, y, z, t) = map(lambda x: int(x), input().split(' '))
	if x == z:
		print(abs(y - t))
		continue
	if a <= y <= b or a <= t <= b:
		print(abs(y - t) + abs(x - z))
		continue
	if (y - a) * (t - a) > 0:
		print(min(abs(y - a), abs(y - b)) + min(abs(t - a), abs(t - b)) + abs(x - z))
		continue
	print(min(abs(y - a), abs(y - b)) + min(abs(t - a), abs(t - b)) + b - a + abs(x - z))


(n, h, a, b, k) = map(int, input().split(' '))
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split(' '))
	ans = 0
	ans += abs(fa - fb) + abs(ta - tb)
	if fa > b and fb > b:
		ans += 2 * (min(fa, fb) - b)
	elif fa < a and fb < a:
		ans += 2 * (a - max(fa, fb))
	if ta == tb:
		ans = abs(fa - fb)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
lst = []
for i in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	l = [t1, f1, t2, f2]
	lst.append(l)

def cal(l):
	tower1 = l[0]
	tower2 = l[2]
	floor1 = l[1]
	floor2 = l[3]
	if tower1 == tower2:
		return abs(floor1 - floor2)
	elif floor1 >= a and floor1 <= b:
		return abs(floor1 - floor2) + abs(tower1 - tower2)
	else:
		return min(abs(a - floor1) + abs(tower1 - tower2) + abs(floor2 - a), abs(b - floor1) + abs(tower1 - tower2) + abs(floor2 - b))
for x in lst:
	print(cal(x))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
		continue
	res = abs(ta - tb) + abs(fa - fb)
	if fa > b and fb > b:
		res += 2 * (min(fa, fb) - b)
	if fa < a and fb < a:
		res += 2 * (a - max(fa, fb))
	print(res)


from sys import stdin

def in_range(c):
	return a <= c <= b

def h_(f_):
	return (min(abs(f_ - a), abs(f_ - b)), 0)[in_range(f_)]

def solve(el_):
	(ta, fa, tb, fb) = el_
	if ta == tb:
		return abs(fa - fb)
	return (abs(ta - tb) + h_(fa) + h_(fb), abs(ta - tb) + abs(fa - fb))[(in_range(fa) or in_range(fb)) or (fa > b and fb < a or (fa < a and fb > b))]
all_in = stdin.readlines()
(n, h, a, b, k) = map(int, all_in[0].split())
inp = [tuple(map(int, el.split())) for el in all_in[1:]]
ans = list()
for el in inp:
	ans.append(solve(el))
print('\n'.join(map(str, ans)))


(n, h, a, b, k) = (int(x) for x in input().split())
for i in range(k):
	(ta, fa, tb, fb) = (int(x) for x in input().split())
	if ta == tb:
		print(abs(fa - fb))
	else:
		ans = abs(ta - tb)
		pr = 0
		if fa <= b and fa >= a:
			pass
		else:
			ans += min(abs(fa - a), abs(fa - b))
		if fb <= b and fb >= a:
			if fa > b:
				ans += b - fb
			elif fa < a:
				ans += fb - a
			else:
				ans += abs(fa - fb)
		elif fa > b and fb > b:
			ans += fb - b
		elif fa > b and fb < a:
			ans += b - fb
		elif fa < a and fb > b:
			ans += fb - a
		elif fa < a and fb < a:
			ans += a - fb
		else:
			ans += abs(fa - fb)
		print(ans)


(n, h, a, b, k) = [int(x) for x in input().split()]

def overlap(x, y):
	if x > y:
		return overlap(y, x)
	if x == a or x == b or y == a or (y == b):
		return True
	if x >= a and y <= b:
		return True
	A = sorted([x, y, a, b])
	return A.index(y) - A.index(x) > 1
for i in range(k):
	(ta, fa, tb, fb) = [int(x) for x in input().split()]
	if ta == tb:
		print(abs(fa - fb))
		continue
	if overlap(fa, fb):
		print(abs(ta - tb) + abs(fa - fb))
	else:
		res = abs(ta - tb)
		if abs(fa - a) < abs(fa - b):
			res += abs(fa - a) + abs(a - fb)
		else:
			res += abs(fa - b) + abs(b - fb)
		print(res)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fb - fa))
		continue
	if fa > fb:
		(tb, ta) = (ta, tb)
		(fb, fa) = (fa, fb)
	if a <= fa and fb <= b or (fa <= a and fb >= b) or a <= fa <= b or (a <= fb <= b):
		ans = abs(tb - ta)
		ans += fb - fa
		print(ans)
		continue
	elif fa > b:
		ans = abs(tb - ta)
		ans += fa - b
		ans += fb - b
		print(ans)
	elif fb < a:
		ans = abs(tb - ta)
		ans += a - fa
		ans += a - fb
		print(ans)


inputA = [int(i) for i in input().split()]
queries = []
for i in range(inputA[4]):
	queries.append([int(j) for j in input().split()])
for i in range(inputA[4]):
	if queries[i][0] == queries[i][2]:
		print(abs(queries[i][1] - queries[i][3]))
	elif queries[i][1] >= inputA[2] and queries[i][1] <= inputA[3]:
		print(abs(queries[i][0] - queries[i][2]) + abs(queries[i][1] - queries[i][3]))
	elif queries[i][1] < inputA[2]:
		print(inputA[2] - queries[i][1] + abs(queries[i][0] - queries[i][2]) + abs(inputA[2] - queries[i][3]))
	elif queries[i][1] > inputA[3]:
		print(queries[i][1] - inputA[3] + abs(queries[i][0] - queries[i][2]) + abs(inputA[3] - queries[i][3]))


(N, H, A, B, K) = map(int, input().split())
ind = 0
while ind < K:
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
	else:
		ans = 0
		if fa >= A and fa <= B:
			ans += abs(fa - fb) + abs(ta - tb)
		elif fa < A:
			ans += abs(fa - A)
			ans += abs(ta - tb)
			ans += abs(A - fb)
		elif fa > B:
			ans += abs(fa - B)
			ans += abs(ta - tb)
			ans += abs(B - fb)
		print(ans)
	ind += 1


(n_tower, h_floor, a, b, k_way) = map(int, input().split())
for i in range(k_way):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		x = abs(fb - fa)
		print(x)
	elif a <= fa <= b:
		x = abs(fb - fa)
		y = abs(tb - ta)
		z = x + y
		print(z)
	elif a > fa:
		x = abs(fa - a)
		t = abs(fb - a)
		y = abs(tb - ta)
		z = x + y + t
		print(z)
	elif fa > b:
		x = abs(fa - b)
		t = abs(fb - b)
		y = abs(tb - ta)
		z = x + y + t
		print(z)


(n, h, a, b, k) = map(int, input().split())
queries = []
for i in range(k):
	temp = list(map(int, input().split()))
	queries.append([(temp[0], temp[1]), (temp[2], temp[3])])
for query in queries:
	(ta, fa, tb, fb) = (query[0][0], query[0][1], query[1][0], query[1][1])
	count = 0
	if (fa < a or fa > b) and ta != tb:
		count += abs(a - fa) if abs(a - fa) < abs(b - fa) else abs(b - fa)
		flag = b
		if abs(a - fa) < abs(b - fa):
			flag = a
		count += abs(ta - tb)
		count += abs(fb - flag)
	else:
		count += abs(ta - tb) + abs(fb - fa)
	print(count)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(Ta, Fa, Tb, Fb) = map(int, input().split())
	dist = abs(Tb - Ta)
	if dist == 0:
		dist = abs(Fb - Fa)
	elif Fa < a:
		dist += abs(Fa - a) + abs(a - Fb)
	elif Fa > b:
		dist += abs(Fa - b) + abs(b - Fb)
	else:
		dist += abs(Fb - Fa)
	print(dist)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(h1, f1, h2, f2) = map(int, input().split())
	if h1 == h2:
		print(abs(f2 - f1))
	elif f1 < a:
		print(a - f1 + abs(h2 - h1) + abs(f2 - a))
	elif f1 > b:
		print(f1 - b + abs(h2 - h1) + abs(f2 - b))
	else:
		print(abs(h2 - h1) + abs(f2 - f1))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(t_a, f_a, t_b, f_b) = map(int, input().split())

	def transfer(floor):
		if floor > b:
			return b
		elif floor < a:
			return a
		return floor
	if t_a == t_b:
		print(abs(f_a - f_b))
	else:
		horizontal = abs(t_a - t_b)
		floor = transfer(f_a)
		vertical = abs(f_a - floor) + abs(f_b - floor)
		print(horizontal + vertical)


(t, f, lw, hw, q) = map(int, input().split())
while q:
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 == t2:
		print(abs(f1 - f2))
	else:
		ans = abs(t1 - t2)
		if f1 >= lw and f1 <= hw or (f2 >= lw and f2 <= hw):
			ans += abs(f1 - f2)
			print(ans)
		elif f1 < lw and f2 < lw:
			ans += abs(lw - f1) + abs(lw - f2)
			print(ans)
		elif f1 > hw and f2 > hw:
			ans += abs(hw - f1) + abs(hw - f2)
			print(ans)
		else:
			if f1 > hw:
				ans += abs(hw - f1) + abs(hw - f2)
			else:
				ans += abs(lw - f1) + abs(lw - f2)
			print(ans)
	q -= 1


(a, b, c, d, e) = list(map(int, input().split()))
for i in range(e):
	(f, g, h, i) = list(map(int, input().split()))
	j = c if c >= g else g if c <= g and g <= d else d
	print(abs(j - g) + abs(j - i) + abs(f - h) if f != h else abs(g - i))


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t, f, t1, f1) = map(int, input().split())
	if t == t1:
		ans = abs(f - f1)
	elif f > b and f1 > b:
		ans = f - b + abs(t - t1) + f1 - b
	elif f > b and f1 < a:
		ans = f + abs(t - t1) - f1
	elif f < a and f1 > b:
		ans = ans = -f + abs(t - t1) + f1
	elif f < a and f1 < a:
		ans = a - f + abs(t - t1) + a - f1
	else:
		ans = abs(t - t1) + abs(f - f1)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	t = 0
	if ta == tb:
		print(abs(fb - fa))
	else:
		t += abs(tb - ta)
		if fa >= a and fa <= b:
			t += abs(fb - fa)
		else:
			if fa < a:
				x = a
			else:
				x = b
			t += min(abs(fa - a), abs(fa - b))
			t += abs(fb - x)
		print(t)


def sol():
	(n, h, a, b, k) = list(map(int, input().split()))
	for i in range(k):
		(build1, block1, build2, block2) = list(map(int, input().split()))
		if build1 == build2:
			print(abs(block2 - block1))
		elif block1 >= a and block1 <= b:
			print(abs(build1 - build2) + abs(block2 - block1))
		elif block1 > b:
			print(abs(build1 - build2) + abs(block2 - b) + abs(block1 - b))
		else:
			print(abs(build1 - build2) + abs(block2 - a) + abs(block1 - a))
sol()


(n, h, a, b, k) = [int(i) for i in input().split()]
for i in range(k):
	ans = 0
	(xs, ys, xf, yf) = [int(i) for i in input().split()]
	if xs != xf:
		if ys < a or ys > b:
			if abs(ys - a) < abs(ys - b):
				ans += abs(ys - a)
				ys = a
			else:
				ans += abs(ys - b)
				ys = b
		ans += abs(xf - xs)
	ans += abs(ys - yf)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
(ta, fa, tb, fb, m) = ([], [], [], [], [])
for i in range(0, k):
	(r1, r2, r3, r4) = map(int, input().split())
	ta.append(r1)
	fa.append(r2)
	tb.append(r3)
	fb.append(r4)
	m.append(abs(ta[i] - tb[i]))
	if m[i] != 0:
		if fa[i] < a:
			m[i] += abs(fa[i] - a)
			m[i] += abs(fb[i] - a)
		elif fa[i] > b:
			m[i] += abs(fa[i] - b)
			m[i] += abs(fb[i] - b)
		else:
			m[i] += abs(fb[i] - fa[i])
	else:
		m[i] += abs(fb[i] - fa[i])
for i in range(0, k):
	print(m[i])


class CodeforcesTask1020ASolution:

	def __init__(self):
		self.result = ''
		self.n_h_a_b_k = []
		self.queries = []

	def read_input(self):
		self.n_h_a_b_k = [int(x) for x in input().split(' ')]
		for x in range(self.n_h_a_b_k[4]):
			self.queries.append([int(y) for y in input().split(' ')])

	def process_task(self):
		results = []
		a = self.n_h_a_b_k[2]
		b = self.n_h_a_b_k[3]
		for query in self.queries:
			cost = abs(query[0] - query[2])
			if a <= query[1] <= b and a <= query[3] <= b:
				cost += abs(query[1] - query[3])
			elif query[1] < a and query[3] > b or (query[1] > b and query[3] < a):
				cost += abs(query[1] - query[3])
			elif query[1] < a and query[3] < a:
				cost += a - query[1] + a - query[3]
			elif query[1] > b and query[3] > b:
				cost += query[1] - b + query[3] - b
			else:
				cost += abs(query[1] - query[3])
			if query[0] == query[2] and query[1] == query[3]:
				cost = 0
			elif query[0] == query[2]:
				cost = abs(query[1] - query[3])
			results.append(cost)
		self.result = '\n'.join([str(x) for x in results])

	def get_result(self):
		return self.result
Solution = CodeforcesTask1020ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, h, a, b, k) = [int(i) for i in input().split()]
while k > 0:
	(ta, fa, tb, fb) = [int(i) for i in input().split()]
	f = a if abs(fa - a) + abs(fb - a) < abs(fa - b) + abs(fb - b) else b
	if ta == tb:
		print(abs(fa - fb))
	elif fa in range(a, b + 1):
		torre = abs(ta - tb)
		print(torre + abs(fa - fb))
	else:
		andar = abs(fa - f) + abs(fb - f)
		torre = abs(ta - tb)
		print(andar + torre)
	k -= 1


def arin():
	arr = list(map(int, input().strip().split(' ')))
	return arr
(n, h, a, b, k) = map(int, input().strip().split(' '))
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().strip().split(' '))
	ans = abs(ta - tb)
	if ta == tb:
		print(abs(fa - fb))
		continue
	if fa >= b:
		ans += fa - b + abs(b - fb)
	elif fa <= a:
		ans += a - fa + abs(a - fb)
	else:
		ans += abs(fa - fb)
	print(ans)


from sys import stdin
inp = lambda : (int(o) for o in stdin.readline().split())
(n, h, a, b, k) = inp()
for _ in [0] * k:
	(ta, fa, tb, fb) = inp()
	if ta == tb:
		print(abs(fa - fb))
	elif fa in range(a, b + 1):
		print(abs(ta - tb) + abs(fa - fb))
	elif fa > b:
		print(abs(ta - tb) + abs(fa - b) + abs(fb - b))
	elif fa < a:
		print(abs(ta - tb) + abs(fa - a) + abs(fb - a))
	else:
		print(abs(ta - tb) + abs(fa - fb))


(n, h, a, b, k) = map(int, input().split())
e = 0
r = ''
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if a <= fa <= b:
		e = abs(tb - ta) + abs(fa - fb)
	elif ta == tb:
		e = abs(fa - fb)
	elif fa > b:
		e = abs(fa - b) + abs(tb - ta) + abs(b - fb)
	elif fa < a:
		e = abs(fa - a) + abs(tb - ta) + abs(fb - a)
	print(e)


def solve(N, H, A, B, Q):
	ans = []
	for (t1, f1, t2, f2) in Q:
		tt = abs(t2 - t1)
		tf = abs(f2 - f1)
		if t1 == t2:
			ans.append(tf)
			continue
		if A <= f1 <= B and A <= f2 <= B:
			ans.append(tt + tf)
			continue
		if f1 > B and f2 > B:
			ans.append(tt + (f1 - B) + (f2 - B))
			continue
		if f1 < A and f2 < A:
			ans.append(tt + (A - f1) + (A - f2))
			continue
		if f1 > B and f2 < A:
			ans.append(tt + (B - A) + (f1 - B) + (A - f2))
			continue
		if f1 < A and f2 > B:
			ans.append(tt + (B - A) + (A - f1) + (f2 - B))
			continue
		ans.append(tt + tf)
	return ans

def main():
	(N, H, A, B, K) = [int(e) for e in input().split(' ')]
	Q = [[int(e) for e in input().split(' ')] for _ in range(K)]
	print(*solve(N, H, A, B, Q), sep='\n')
main()


(n, h, a, b, k) = map(int, input().split(' '))
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split(' '))
	if ta == tb:
		print(abs(fa - fb))
	else:
		t1 = 0
		if fa <= a:
			t1 = a - fa
			fa = a
		elif fa >= b:
			t1 = fa - b
			fa = b
		t2 = abs(fa - fb)
		t3 = abs(ta - tb)
		print(t1 + t2 + t3)


(tower, lantai, a, b, test) = map(int, input().split())
for z in range(test):
	(tawal, fawal, takhir, fakhir) = map(int, input().split())
	if tawal == takhir:
		pindah = abs(fawal - fakhir)
	elif a <= fawal and fawal <= b:
		pindah = abs(takhir - tawal) + abs(fakhir - fawal)
	elif abs(a - fawal) < abs(b - fawal):
		pindah = abs(a - fawal) + abs(takhir - tawal) + abs(a - fakhir)
	else:
		pindah = abs(b - fawal) + abs(takhir - tawal) + abs(b - fakhir)
	print(pindah)


qq = lambda : map(int, input().split())
(n, h, a, b, k) = qq()
ans = 0
x = []
z = 0
q = 0
for i in range(k):
	ans = 0
	(ta, fa, tb, fb) = qq()
	ans += abs(ta - tb)
	if ta == tb:
		ans += abs(fa - fb)
	elif a <= fa and fa <= b:
		ans += abs(fa - fb)
	elif fa < a:
		z = a - fa
		ans += abs(fb - a) + z
	else:
		z = fa - b
		ans += abs(fb - b) + z
	x.append(ans)
for i in x:
	print(i)


(n, h, a, b, k) = map(int, input().split(' '))
for i in range(k):
	(x, y, xx, yy) = map(int, input().split(' '))
	if x == xx:
		print(abs(y - yy))
	else:
		if yy < y:
			(yy, y) = (y, yy)
			(xx, x) = (x, xx)
		ans = abs(x - xx)
		if a < y and b >= y:
			ans += yy - y
		elif a <= yy and b > yy:
			ans += yy - y
		elif a >= y and b <= yy:
			ans += yy - y
		elif a > yy:
			ans += yy - y + (a - yy) * 2
		else:
			ans += yy - y + (y - b) * 2
		print(ans)


(n, h, a, b, k) = [int(x) for x in input().split()]
for _ in range(k):
	(t1, f1, t2, f2) = [int(x) for x in input().split()]
	ans = 0
	ans = abs(t1 - t2)
	if f1 <= b and f1 >= a:
		ans += abs(f1 - f2)
	elif t1 != t2:
		if abs(f1 - a) < abs(f1 - b):
			mina = abs(f1 - a)
			num = a
		else:
			mina = abs(f1 - b)
			num = b
		ans += mina
		ans += abs(f2 - num)
	else:
		ans += abs(f2 - f1)
	print(ans)


def abs(num):
	return num if num >= 0 else -num
(n, h, a, b, k) = map(int, input().split())

def floor_dist(fa, fb):
	if fa > b and fb > b:
		return fa - b + fb - b
	elif fa > b:
		return fa - fb
	elif fb > b:
		return fb - fa
	elif fa < a and fb < a:
		return a - fa + a - fb
	elif fa < a:
		return fb - fa
	else:
		return abs(fb - fa)

def closest_path(ta, fa, tb, fb):
	if ta == tb:
		return abs(fa - fb)
	return abs(ta - tb) + floor_dist(fa, fb)
for x in range(k):
	print(closest_path(*map(int, input().split())))


l = list(map(int, input().split()))
n2 = l[-1]
a = l[2]
b = l[3]
while n2:
	k = list(map(int, input().strip().split()))
	if k[0] == k[2]:
		print(abs(k[1] - k[3]))
	elif k[1] >= a and k[1] <= b:
		print(abs(k[3] - k[1]) + abs(k[2] - k[0]))
	elif k[1] <= a:
		print(abs(a - k[1]) + abs(k[3] - a) + abs(k[2] - k[0]))
	elif k[1] >= b:
		print(abs(k[1] - b) + abs(k[3] - b) + abs(k[2] - k[0]))
	n2 -= 1


i = lambda : map(int, input().split())
(n, h, a, b, k) = i()
for _ in range(k):
	(b1, f1, b2, f2) = i()
	if b1 == b2:
		print(abs(f1 - f2))
	else:
		temp = 0
		if f1 <= b and f1 >= a:
			temp = f1
		elif f1 > b:
			temp = b
		else:
			temp = a
		print(abs(temp - f1) + abs(b1 - b2) + abs(temp - f2))


def solve(ta, tb, fa, fb, a, b):
	hdist = abs(ta - tb)
	vdist = 0
	if hdist:
		if fa > b:
			vdist += abs(fa - b)
			fa = b
		if fa < a:
			vdist += abs(a - fa)
			fa = a
		if fb < a:
			vdist += abs(a - fb)
			fb = a
		if fb > b:
			vdist += abs(fb - b)
			fb = b
	vdist += abs(fa - fb)
	return hdist + vdist
(n, h, a, b, k) = map(int, input().split())
for query in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	print(solve(ta, tb, fa, fb, a, b))


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(n, h, a, b, k) = list(map(int, input().split(' ')))
	for _ in range(k):
		(ta, fa, tb, fb) = list(map(int, input().split(' ')))
		if ta == tb:
			ans = abs(fa - fb)
		else:
			ans = abs(ta - tb)
			if fa > fb:
				(fa, fb) = (fb, fa)
			if a <= fa <= b or fa <= a <= fb:
				ans += fb - fa
			elif fa >= b:
				ans += fa - b + fb - b
			elif fb <= a:
				ans += a - fa + a - fb
		print(ans)

def __starting_point():
	main()
__starting_point()


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	d = 0
	f = fa
	t = ta
	if ta != tb:
		dist_a = abs(a - fa)
		dist_b = abs(b - fa)
		if not a <= fa <= b:
			if dist_a < dist_b:
				f = a
				d += dist_a
			else:
				f = b
				d += dist_b
		t = tb
		d += abs(ta - tb)
	d += abs(f - fb)
	print(d)


def p(t1, f1, t2, f2, h, a, b):
	if t1 == t2:
		return abs(f2 - f1)
	elif b >= f1 >= a:
		return abs(t2 - t1) + abs(f2 - f1)
	elif a > f1:
		return abs(a - f1) + abs(t2 - t1) + abs(f2 - a)
	else:
		return min(abs(b - f1) + abs(b - f2) + abs(t2 - t1), abs(f1 - a) + abs(f2 - a) + abs(t2 - t1))
(n, h, a, b, k) = [int(i) for i in input().split()]
tmp = []
for i in range(k):
	(t1, f1, t2, f2) = [int(i) for i in input().split()]
	print(p(t1, f1, t2, f2, h, a, b))


(n, h, a, b, k) = [int(x) for x in input().split()]
for i in range(0, k):
	(ta, fa, tb, fb) = [int(x) for x in input().split()]
	if ta == tb:
		print(abs(fa - fb))
		continue
	elif fa > b:
		mini = abs(fa - b)
		mini2 = abs(fb - b)
		temp = abs(tb - ta)
		ans = mini + mini2 + temp
		print(ans)
		continue
	elif fa < a:
		mini = abs(a - fa)
		mini2 = abs(a - fb)
		temp = abs(tb - ta)
		ans = mini + mini2 + temp
		print(ans)
		continue
	else:
		temp = abs(tb - ta)
		mini = abs(fb - fa)
		ans = mini + temp
		print(ans)
		continue


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
		continue
	ans = 10 ** 10
	if a <= fa <= b:
		ans = abs(ta - tb) + abs(fa - fb)
	ans = min(ans, abs(a - fa) + abs(ta - tb) + abs(a - fb))
	ans = min(ans, abs(b - fa) + abs(ta - tb) + abs(b - fb))
	print(ans)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	res = abs(f1 - f2) + abs(t1 - t2)
	if t1 != t2 and min(f1, f2) > b:
		res += min(f1 - b, f2 - b) * 2
	if t1 != t2 and max(f1, f2) < a:
		res += min(a - f1, a - f2) * 2
	print(res)


(n, h, a, b, k) = map(int, input().split())
mas = []
for i in range(k):
	q = 0
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		q += abs(fb - fa)
	else:
		if fa >= b:
			q += fa - b
			fa = b
		elif fa <= a:
			q += a - fa
			fa = a
		q += abs(tb - ta)
		q += abs(fb - fa)
	mas.append(str(q))
print('\n'.join(mas))


import sys
(n, h, a, b, k) = map(int, sys.stdin.readline().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, sys.stdin.readline().split())
	if ta == tb:
		dist = abs(fa - fb)
	elif a <= fa <= b or a <= fb <= b:
		dist = abs(fa - fb) + abs(ta - tb)
	else:
		dist1_upper = abs(fa - b)
		dist1_lower = abs(fa - a)
		dist2_upper = abs(fb - b)
		dist2_lower = abs(fb - a)
		dist_towers = abs(ta - tb)
		dist1 = dist1_upper + dist2_upper + dist_towers
		dist2 = dist1_lower + dist2_lower + dist_towers
		dist = min(dist1, dist2)
	sys.stdout.write(str(dist) + '\n')


import math

def main():
	[n, h, a, b, k] = [int(x) for x in input().split()]
	for i in range(k):
		minDistance = 0
		[x0, y0, x1, y1] = [int(x) for x in input().split()]
		minDistance += int(math.fabs(x0 - x1))
		if minDistance > 0 and y0 > b and (y1 > b):
			minDistance += int(math.fabs(y0 - b))
			minDistance += int(math.fabs(y1 - b))
		elif minDistance > 0 and y0 < a and (y1 < a):
			minDistance += int(math.fabs(a - y0))
			minDistance += int(math.fabs(a - y1))
		else:
			minDistance += int(math.fabs(y0 - y1))
		print(minDistance)
main()


import functools
import time
from collections import Counter

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		(n, h, a, b, k) = map(int, input().strip().split())
		for _ in range(k):
			(ta, fa, tb, fb) = map(int, input().strip().split())
			if ta == tb:
				ans = abs(fa - fb)
			else:
				if fa < fb:
					(fa, fb) = (fb, fa)
					(ta, tb) = (tb, ta)
				if fa >= b:
					if fb <= b:
						ans = abs(ta - tb) + abs(fa - fb)
					else:
						ans = abs(ta - tb) + abs(fa - b) + abs(fb - b)
				elif a <= fa and fa < b:
					ans = abs(ta - tb) + abs(fa - fb)
				else:
					ans = abs(ta - tb) + abs(fa - a) + abs(fb - a)
			print(ans)
solver()()


(n, h, i, j, m) = map(int, input().split())
for k in range(m):
	(b1, e1, b2, e2) = map(int, input().split())
	if b1 == b2:
		print(abs(e2 - e1))
	elif i <= e2 <= j:
		print(abs(b1 - b2) + abs(e1 - e2))
	elif e2 > j:
		print(abs(b1 - b2) + abs(e1 - j) + abs(e2 - j))
	else:
		print(abs(b1 - b2) + abs(e1 - i) + abs(e2 - i))


from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
h = int(line[1])
a = int(line[2])
b = int(line[3])
k = int(line[4])
for i in range(k):
	numbers = list(map(int, stdin.readline().rstrip().split()))
	ta = numbers[0]
	fa = numbers[1]
	tb = numbers[2]
	fb = numbers[3]
	if ta == tb:
		print(abs(fa - fb))
	else:
		total = 0
		if fa < a:
			total += a - fa
			total += abs(fb - a)
		elif fa > b:
			total += fa - b
			total += abs(fb - b)
		else:
			total += abs(fa - fb)
		total += abs(ta - tb)
		print(total)


import sys
import io
stream_enable = 0
inpstream = '\n3 6 2 3 3\n1 2 1 3\n1 4 3 4\n1 2 2 3\n\n'
if stream_enable:
	sys.stdin = io.StringIO(inpstream)
	input()

def inpmap():
	return list(map(int, input().split()))
(n, h, a, b, k) = inpmap()
for i in range(k):
	(ta, fa, tb, fb) = inpmap()
	r = 0
	if ta != tb:
		if fa > b:
			r += fa - b
			fa = b
		if fa < a:
			r += a - fa
			fa = a
	r += abs(ta - tb)
	r += abs(fa - fb)
	print(r)


(n, h, a, b, k) = list(map(int, input().strip().split()))
for i in range(k):
	(ta, fa, tb, fb) = list(map(int, input().strip().split()))
	ans = 0
	to = fa
	if ta == tb:
		print(abs(fa - fb))
		continue
	if fa > b:
		ans = fa - b
		to = b
	if fa < a:
		ans = a - fa
		to = a
	ans += abs(tb - ta)
	ans += abs(fb - to)
	print(ans)


(N, H, A, B, K) = [int(x) for x in input().split(' ')]
for k in range(K):
	(ta, fa, tb, fb) = [int(x) for x in input().split(' ')]
	t = 0
	if ta == tb:
		t += abs(fa - fb)
	else:
		if fa >= A and fa <= B:
			t += 0
		elif fa < A:
			t += A - fa
			fa = A
		elif fa > B:
			t += fa - B
			fa = B
		t += abs(ta - tb)
		t += abs(fa - fb)
	print(t)


(tow_nr, fl_nr, l_cl, r_cl, req_nr) = (int(x) for x in input().split())
for _ in range(req_nr):
	(t1, f1, t2, f2) = (int(x) for x in input().split())
	ans = 0
	if f1 < l_cl and t1 != t2:
		ans += l_cl - f1
		f1 = l_cl
	if f1 > r_cl and t1 != t2:
		ans += f1 - r_cl
		f1 = r_cl
	ans += abs(t1 - t2)
	ans += abs(f1 - f2)
	print(ans)


Y = list(map(int, input().split()))
n = Y[0]
h = Y[1]
a = Y[2]
b = Y[3]
k = Y[4]
for i in range(k):
	A = list(map(int, input().split()))
	if A[0] == A[2]:
		ans = abs(A[1] - A[3])
	elif A[1] < a:
		ans = abs(A[0] - A[2]) + a - A[1] + abs(a - A[3])
	elif A[1] > b:
		ans = abs(A[0] - A[2]) + A[1] - b + abs(b - A[3])
	else:
		ans = abs(A[0] - A[2]) + abs(A[1] - A[3])
	print(ans)


(t, h, a, b, k) = map(int, input().split())
ans = []
(s, s1) = (0, 0)
for i in range(k):
	che = 0
	(x, y, xx, yy) = map(int, input().split())
	che += max(x, xx) - min(x, xx)
	if che == 0:
		che += max(y, yy) - min(y, yy)
	elif a <= y <= b or a <= yy <= b:
		che += max(yy, y) - min(yy, y)
	else:
		(s, s1) = (a - min(y, yy), max(y, yy) - b)
		if s > 0 and s1 > 0:
			che += max(yy, y) - min(yy, y)
		elif s > 0 and s1 < 0:
			che += s + a - max(yy, y)
		elif s < 0 and s1 > 0:
			che += s1 + min(yy, y) - b
	ans.append(che)
print(*ans, sep='\n')


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(tower_a, floor_a, tower_b, floor_b) = map(int, input().split())
	if tower_a == tower_b:
		print(abs(floor_a - floor_b))
	elif a <= floor_a <= b:
		print(abs(floor_a - floor_b) + abs(tower_b - tower_a))
	else:
		if a > floor_a:
			walk_to_passage = a - floor_a
			floor_a = a
		else:
			walk_to_passage = floor_a - b
			floor_a = b
		print(abs(floor_a - floor_b) + abs(tower_b - tower_a) + walk_to_passage)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	(n, h, l, r, q) = inar()
	for i in range(q):
		(ta, fa, tb, fb) = inar()
		if ta == tb:
			print(abs(fa - fb))
		elif (fa < l or fa > r) and (fb < l or fb > r):
			if fa < l and fb < l:
				print(abs(ta - tb) + (l - fa) + (l - fb))
			elif fa > r and fb > r:
				print(abs(ta - tb) + (fa - r) + (fb - r))
			else:
				print(abs(ta - tb) + abs(fa - fb))
		else:
			print(abs(ta - tb) + abs(fa - fb))
main()


(n, h, a, b, k) = map(int, input().split())
answer = []
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	time = 0
	if ta == tb:
		time += abs(fa - fb)
		answer.append(time)
		continue
	if a <= fa <= b:
		time += abs(ta - tb)
		time += abs(fa - fb)
		answer.append(time)
		continue
	elif fa > b:
		time += abs(fa - b)
		time += abs(ta - tb)
		time += abs(b - fb)
		answer.append(time)
		continue
	else:
		time += abs(fa - a)
		time += abs(ta - tb)
		time += abs(a - fb)
		answer.append(time)
		continue
for i in answer:
	print(i, end='\n')


(n, h, a, b, k) = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(k)]

def res(x1, y1, x2, y2):
	cnt = abs(x1 - x2)
	where = 0
	if x1 == x2:
		return abs(y1 - y2)
	if y1 < a:
		cnt += a - y1
		where = a
	elif y1 > b:
		cnt += y1 - b
		where = b
	else:
		where = y1
	return cnt + abs(where - y2)
for i in range(k):
	print(res(x[i][0], x[i][1], x[i][2], x[i][3]))


(n, h, a, b, k) = [int(i) for i in input().split()]
for q in range(k):
	(ta, fa, tb, fb) = [int(i) for i in input().split()]
	if ta == tb:
		print(abs(fb - fa))
	else:
		ans = 0
		cur = 0
		if fa >= a and fa <= b:
			ans += abs(tb - ta)
			cur = '-'
		elif abs(fa - a) < abs(fa - b):
			cur = 'a'
			ans += abs(fa - a)
		else:
			cur = 'b'
			ans += abs(fa - b)
		if cur == 'a':
			ans += abs(tb - ta)
			ans += abs(fb - a)
		elif cur == 'b':
			ans += abs(tb - ta)
			ans += abs(fb - b)
		elif cur == '-':
			ans += abs(fb - fa)
		print(ans)


from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
import sys
sys.setrecursionlimit(1000000)

def io():
	return map(int, input().split())

def op():
	return list(map(int, input().split()))

def o():
	return int(input())

def kl(con, x=0):
	if x == 0:
		print('Yes') if con else print('No')
	elif x == 1:
		print('yes') if con else print('no')
	elif x == 2:
		print('YES') if con else print('NO')
MOD = 1000000007
MAX = 2147483647
MIN = -2147483648
p = input
n = 0
(n, h, a, b, k) = io()
for i in range(k):
	(ta, fa, tb, fb) = io()
	if ta == tb:
		print(abs(fa - fb))
	elif fa < a and fb < a:
		print(abs(fa - a) + abs(fb - a) + abs(ta - tb))
	elif fa > b and fb > b:
		print(abs(fa - b) + abs(fb - b) + abs(ta - tb))
	else:
		print(abs(fa - fb) + abs(ta - tb))


def find_location(f, a, b):
	if f < a:
		return 1
	elif f > b:
		return 3
	else:
		return 2
(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	l1 = find_location(fa, a, b)
	l2 = find_location(fb, a, b)
	if ta == tb:
		print(abs(fa - fb))
	elif l1 == 1 and l2 == 1:
		print(a - fb + a - fa + abs(ta - tb))
	elif l1 == 1 and l2 == 2:
		print(fb - fa + abs(ta - tb))
	elif l1 == 1 and l2 == 3:
		print(fb - fa + abs(ta - tb))
	elif l1 == 2 and l2 == 1:
		print(fa - fb + abs(ta - tb))
	elif l1 == 2 and l2 == 2:
		print(abs(fb - fa) + abs(ta - tb))
	elif l1 == 2 and l2 == 3:
		print(fb - fa + abs(ta - tb))
	elif l1 == 3 and l2 == 1:
		print(fa - fb + abs(ta - tb))
	elif l1 == 3 and l2 == 2:
		print(fa - fb + abs(ta - tb))
	elif l1 == 3 and l2 == 3:
		print(fb - b + fa - b + abs(ta - tb))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, h, a, b, k) = LI()
	aa = [LI() for _ in range(k)]
	r = []
	for (t1, f1, t2, f2) in aa:
		if t1 == t2:
			r.append(abs(f1 - f2))
		else:
			t = abs(t1 - t2)
			if f1 > b:
				t += f1 - b
				t += abs(f2 - b)
			elif f1 < a:
				t += a - f1
				t += abs(f2 - a)
			else:
				t += abs(f1 - f2)
			r.append(t)
	return '\n'.join(map(str, r))
print(main())


def solve(q, a, b, k):
	ans = []
	for i in range(k):
		ans1 = abs(q[i][0] - q[i][2])
		if a <= q[i][1] <= b or q[i][0] == q[i][2]:
			ans2 = abs(q[i][1] - q[i][3])
			ans.append(ans1 + ans2)
		else:
			if abs(a - q[i][1]) < abs(b - q[i][1]):
				ans2 = abs(a - q[i][1])
				ans3 = abs(a - q[i][3])
			else:
				ans2 = abs(b - q[i][1])
				ans3 = abs(b - q[i][3])
			ans.append(ans1 + ans2 + ans3)
	return ans

def main():
	(n, h, a, b, k) = map(int, input().split())
	q = []
	for i in range(k):
		(w, x, y, z) = map(int, input().split())
		q.append((w, x, y, z))
	ans = solve(q, a, b, k)
	for i in range(len(ans)):
		print(ans[i])
main()


q = input()
q = q.split()
n = int(q[0])
h = int(q[1])
a = int(q[2])
b = int(q[3])
k = int(q[4])
z = 0
zz = 0
for i in range(k):
	qq = input()
	qqq = qq.split()
	z = 0
	zz = int(qqq[1])
	if qqq[0] != qqq[2]:
		if int(qqq[1]) < a:
			z = a - int(qqq[1])
			zz = a
		if int(qqq[1]) > b:
			z = int(qqq[1]) - b
			zz = b
		z = z + abs(int(qqq[0]) - int(qqq[2]))
	z = z + abs(zz - int(qqq[3]))
	print(z)


(n, h, a, b, k) = [int(i) for i in input().split()]
for ii in range(k):
	(t1, f1, t2, f2) = [int(i) for i in input().split()]
	ans = abs(t2 - t1)
	if t2 != t1:
		if f1 < a:
			ans += a - f1
			f1 = a
		elif f1 > b:
			ans += f1 - b
			f1 = b
		if f2 < a:
			ans += a - f2
			f2 = a
		elif f2 > b:
			ans += f2 - b
			f2 = b
	ans += abs(f1 - f2)
	print(ans)


from sys import stdin, stdout

def main():
	(n, h, a, b, k) = [int(x) for x in stdin.readline().split()]
	for i in range(k):
		(ta, fa, tb, fb) = [int(x) for x in stdin.readline().split()]
		if ta == tb:
			stdout.write(str(abs(fa - fb)))
			print()
			continue
		c = abs(ta - tb)
		s = 0
		t = 0
		if fa >= a and fa <= b:
			s = fa
		elif fa < a:
			s = a
			c += a - fa
		else:
			s = b
			c += fa - b
		if fb >= a and fb <= b:
			t = fb
		elif fb < a:
			t = a
			c += a - fb
		else:
			t = b
			c += fb - b
		c += abs(t - s)
		stdout.write(str(c))
		print()
main()


(t, f, a, b, q) = map(int, input().split())
for i in range(q):
	(ts, fs, te, fe) = map(int, input().split())
	if fs >= a and fs <= b or (fe >= a and fe <= b) or ts == te:
		print(abs(ts - te) + abs(fs - fe))
	else:
		print(abs(ts - te) + min(abs(fs - a) + abs(fe - a), abs(fs - b) + abs(fe - b)))


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
	else:
		mid = max(a, min(b, fa))
		print(abs(ta - tb) + abs(fa - mid) + abs(fb - mid))


from sys import setrecursionlimit
f = lambda : map(int, input().split())
(n, h, a, b, k) = f()
for _ in range(k):
	(ta, fa, tb, fb) = f()
	if ta == tb:
		print(abs(fa - fb))
	elif fa > b:
		print(abs(ta - tb) + fa - b + abs(fb - b))
	elif fa < a:
		print(abs(ta - tb) + a - fa + abs(fb - a))
	elif a <= fa <= b:
		print(abs(ta - tb) + abs(fb - fa))


import math
(n, h, a, b, k) = map(int, input().split())
while k > 0:
	k -= 1
	(ta, fa, tb, fb) = map(int, input().split())
	ans = 0
	if ta == tb:
		ans = math.fabs(fa - fb)
	elif fa > b:
		ans = fa - b + math.fabs(fb - b) + math.fabs(ta - tb)
	elif fa < a:
		ans = a - fa + math.fabs(fb - a) + math.fabs(ta - tb)
	else:
		ans = math.fabs(fa - fb) + math.fabs(ta - tb)
	print(int(ans))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	num = 0
	(p, q, r, s) = map(int, input().split())
	if p == r:
		num = abs(q - s)
	elif a <= q <= b:
		num += abs(p - r)
		num += abs(q - s)
	elif b < q:
		num += q - b
		num += abs(p - r)
		num += abs(b - s)
	else:
		num += a - q
		num += abs(p - r)
		num += abs(a - s)
	print(num)


(n, h, a, b, k) = [int(x) for x in input().split()]
for i in range(k):
	(sb, se, fb, fe) = [int(x) for x in input().split()]
	if se >= a and se <= b or (fe >= a and se <= b) or sb == fb or (se < a and fe > b) or (fe < a and se > b):
		ans = abs(sb - fb) + abs(se - fe)
	elif se > b:
		ans = abs(se - b) + abs(sb - fb) + abs(fe - b)
	elif se < a:
		ans = abs(a - se) + abs(sb - fb) + abs(a - fe)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
while k:
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
	elif fa >= a and fb <= b:
		print(abs(ta - tb) + abs(fa - fb))
	else:
		print(abs(ta - tb) + min(abs(fa - a) + abs(a - fb), abs(fa - b) + abs(b - fb)))
	k = k - 1


import math

def main():
	data = list(map(int, input().split()))
	queies = []
	for i in range(data[4]):
		queies.append(list(map(int, input().split())))
	for i in range(data[4]):
		total_time = 0
		if queies[i][0] == queies[i][2]:
			total_time = abs(queies[i][3] - queies[i][1])
		elif queies[i][1] > data[2] and queies[i][1] < data[3]:
			total_time = abs(queies[i][3] - queies[i][1]) + abs(queies[i][0] - queies[i][2])
		else:
			temp = data[2] if abs(queies[i][1] - data[2]) < abs(queies[i][1] - data[3]) else data[3]
			total_time = abs(queies[i][1] - temp) + abs(queies[i][0] - queies[i][2]) + abs(queies[i][3] - temp)
		print(total_time)
main()


testing = False
import sys
data = []
lines = 4

def toInts(xs):
	return list(map(int, xs))
fst = sys.stdin.readline().split()
(n, h, lowerbound, upperbound, k) = [int(x) for x in fst]
lines = k
if testing:
	print(k)

def dist(j, k):
	return abs(j - k)
pasadizos = range(lowerbound, upperbound + 1)

def roadSteps(data):
	(building1, floor1, building2, floor2) = data
	if (building1, floor1) == (building2, floor2):
		return 0
	elif building1 == building2:
		return dist(floor1, floor2)
	elif floor1 in pasadizos:
		return dist(building1, building2) + dist(floor1, floor2)
	elif floor1 > upperbound:
		return dist(floor1, upperbound) + dist(building1, building2) + dist(upperbound, floor2)
	else:
		return dist(floor1, lowerbound) + dist(building1, building2) + dist(lowerbound, floor2)
for line in sys.stdin:
	twoClassroms = [int(x) for x in line.split()]
	steps = roadSteps(twoClassroms)
	lines -= 1
	if testing:
		print(line.split())
		print('solved the problem with these number of minutes')
		print(f'{lines} lines left')
	print(steps)
	if lines == 0:
		break


import math

def main_function():
	(n, h, a, b, k) = [int(i) for i in input().split(' ')]
	queries = [[int(i) for i in input().split(' ')] for d in range(k)]
	for i in queries:
		counter = 0
		(t_a, f_a, t_b, f_b) = i
		if t_a != t_b:
			if f_a > b:
				counter += f_a - b
				final = b
			elif f_a < a:
				counter += a - f_a
				final = a
			else:
				final = f_a
			counter += abs(t_a - t_b)
			counter += abs(final - f_b)
		else:
			counter += abs(f_a - f_b)
		print(counter)
main_function()


(n_tower, h_floor, a, b, k_way) = map(int, input().split())
for i in range(k_way):
	(t1, f1, t2, f2) = map(int, input().split())
	t = abs(t2 - t1)
	f = abs(f2 - f1)
	if t == 0:
		print(f)
	elif f1 >= a and f1 <= b or (f2 >= a and f2 <= b):
		print(f + t)
	elif f1 > b:
		print(t + abs(f1 - b) + abs(f2 - b))
	elif f1 < a:
		print(t + abs(f1 - a) + abs(f2 - a))


(n, h, a, b, k) = [int(i) for i in input().split()]
for w in range(k):
	(ta, fa, tb, fb) = [int(i) for i in input().split()]
	ans = 0
	skyWay = 0
	if ta == tb:
		print(max(fa, fb) - min(fa, fb))
		continue
	if fa > b:
		ans += fa - b
		skyWay = b
	elif fa < a:
		ans += a - fa
		skyWay = a
	else:
		skyWay = fa
	ans += max(tb, ta) - min(ta, tb)
	if fb > skyWay:
		ans += fb - skyWay
	elif fb < skyWay:
		ans += skyWay - fb
	print(ans)


import math
(n, h, a, b, k) = map(int, input().strip().split())
for i in range(k):
	c = 0
	(ta, fa, tb, fb) = map(int, input().strip().split())
	if ta == tb:
		print(int(math.fabs(fa - fb)))
		continue
	l = fa
	if fa > b or fa < a:
		if math.fabs(fa - a) < math.fabs(fa - b):
			c += math.fabs(fa - a)
			l = a
		else:
			c += math.fabs(fa - b)
			l = b
	c += math.fabs(fb - l)
	c += math.fabs(tb - ta)
	print(int(c))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(w_a, h_a, w_b, h_b) = map(int, input().split())
	ans = abs(w_a - w_b)
	if w_a == w_b:
		ans = abs(h_a - h_b)
		print(ans)
		continue
	cur_height = 1
	if a <= h_a <= b:
		cur_height = h_a
	else:
		cur_height = b if abs(h_a - b) < abs(h_a - a) else a
	ans += abs(cur_height - h_a)
	ans += abs(cur_height - h_b)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	ans = 0
	(nb1, ne1, nb2, ne2) = map(int, input().split())
	if nb1 == nb2:
		ans = abs(ne1 - ne2)
	else:
		closego = ne1
		if not a < ne1 < b:
			closego = a if abs(ne1 - a) < abs(ne1 - b) else b
		ans = abs(ne1 - closego)
		ans += abs(nb1 - nb2)
		ans += abs(ne2 - closego)
	print(ans)


(n, h, a, b, k) = map(int, input().split())
inpL = []
for z in range(k):
	thisLine = [int(x) for x in input().split()]
	inpL.append(thisLine)
for i in range(k):
	if inpL[i][0] == inpL[i][2]:
		print(abs(inpL[i][1] - inpL[i][3]))
	else:
		ans1 = abs(inpL[i][0] - inpL[i][2])
		ans2 = abs(inpL[i][0] - inpL[i][2])
		if not (a <= inpL[i][1] <= b or b <= inpL[i][1] <= a):
			ans1 += min(abs(a - inpL[i][1]), abs(inpL[i][1] - a))
			ans2 += min(abs(b - inpL[i][1]), abs(inpL[i][1] - b))
			print(min(ans1 + abs(a - inpL[i][3]), ans2 + abs(b - inpL[i][3])))
		else:
			print(ans1 + abs(inpL[i][3] - inpL[i][1]))


inp = input().split(' ')
for i in range(len(inp)):
	inp[i] = int(inp[i])
(n, h, a, b, k) = inp
queries = []
for i in range(k):
	q = input().split(' ')
	for i in range(len(q)):
		q[i] = int(q[i])
	queries.append(q)
for query in queries:
	(t1, f1, t2, f2) = query
	distance = abs(t2 - t1)
	if a <= f1 <= b or t1 == t2:
		distance += abs(f2 - f1)
	elif f1 < a:
		distance += a - f1 + abs(f2 - a)
	else:
		distance += f1 - b + abs(f2 - b)
	print(distance)


(n, h, a, b, k) = map(int, input().strip().split())
for i in range(k):
	(x1, y1, x2, y2) = map(int, input().strip().split())
	ans = 0
	t = y1
	if x1 != x2:
		if y1 < a:
			ans += a - y1
			t = a
		elif y1 > b:
			ans += y1 - b
			t = b
	ans += abs(x2 - x1)
	ans += abs(y2 - t)
	print(ans)


import sys
import random
from math import log2, log, ceil
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a > 0:
		return gcd(b % a, a)
	return b

def primefs(n):
	if n == 1:
		return 1
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]
spf_sieve()

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
(n, h, a, b, k) = int_array()
for _ in range(k):
	(ta, ha, tb, hb) = int_array()
	ans = abs(ta - tb)
	if ans != 0:
		if ha > b:
			ans += abs(ha - b) + abs(hb - b)
		elif ha < a:
			ans += abs(a - ha) + abs(a - hb)
		else:
			ans += abs(hb - ha)
	else:
		ans = abs(ha - hb)
	print(ans)


s = input().split()
n = int(s[0])
h = int(s[1])
floor1 = int(s[2])
floor2 = int(s[3])
t = int(s[4])
for i in range(t):
	require = input().split()
	start_x = int(require[0])
	start_y = int(require[1])
	end_x = int(require[2])
	end_y = int(require[3])
	ans = 0
	ans = max(start_x, end_x) - min(start_x, end_x)
	if start_x != end_x:
		if start_y >= floor1 and start_y <= floor2:
			ans = ans + abs(start_y - end_y)
		else:
			Try1 = max(floor1, start_y) - min(floor1, start_y) + max(floor1, end_y) - min(floor1, end_y)
			Try2 = max(floor2, start_y) - min(floor2, start_y) + max(floor2, end_y) - min(floor2, end_y)
			ans = ans + min(Try1, Try2)
	else:
		ans = ans + max(end_y, start_y) - min(start_y, end_y)
	print(ans)


inpt = input().split()
(n, h, a, b, k) = (int(inpt[0]), int(inpt[1]), int(inpt[2]), int(inpt[3]), int(inpt[4]))
for t in range(k):
	inpt = input().split()
	(ta, fa, tb, fb) = (int(inpt[0]), int(inpt[1]), int(inpt[2]), int(inpt[3]))
	if ta != tb:
		tmp = abs(tb - ta)
		if fa >= a and fa <= b:
			start = fa
		elif abs(fa - a) < abs(fa - b):
			start = a
			tmp += abs(fa - a)
		else:
			start = b
			tmp += abs(fa - b)
		tmp += abs(fb - start)
	else:
		tmp = abs(fa - fb)
	print(tmp)


s = input().split()
(n, h, a, b, k) = (int(s[0]), int(s[1]), int(s[2]), int(s[3]), int(s[4]))
for que in range(k):
	s = input().split()
	(ta, fa, tb, fb) = (int(s[0]), int(s[1]), int(s[2]), int(s[3]))
	if ta == tb:
		print(abs(fa - fb))
	elif a <= fa <= b:
		print(abs(fa - fb) + abs(ta - tb))
	elif fa < a:
		print(abs(a - fa) + abs(a - fb) + abs(ta - tb))
	elif fa > b:
		print(abs(b - fa) + abs(b - fb) + abs(ta - tb))


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(a_t, a_f, b_t, b_f) = map(int, input().split())
	numtow = abs(b_t - a_t)
	if numtow == 0:
		print(abs(b_f - a_f))
	elif b_f >= b and a_f >= b:
		print(numtow + abs(b_f - b) + abs(a_f - b))
	elif b_f <= a and a_f <= a:
		print(numtow + abs(b_f - a) + abs(a_f - a))
	else:
		print(numtow + abs(b_f - a_f))


d = list(map(int, input().split()))
n = d[0]
h = d[1]
a = d[2]
b = d[3]
k = d[4]
ans = []
for i in range(k):
	t = 0
	d = list(map(int, input().split()))
	ta = d[0]
	fa = d[1]
	tb = d[2]
	fb = d[3]
	if ta == tb:
		ans.append(abs(fa - fb))
	elif fa > b:
		ans.append(fa - b + abs(ta - tb) + abs(b - fb))
	elif fa < a:
		ans.append(a - fa + abs(ta - tb) + abs(a - fb))
	else:
		ans.append(abs(ta - tb) + abs(fa - fb))
for i in range(k):
	print(ans[i])


(n, h, a, b, k) = map(int, input().split())
l = []
for i in range(k):
	l.append(list(map(int, input().split())))
for i in l:
	if i[0] == i[2]:
		print(abs(i[1] - i[3]))
	else:
		time = abs(i[0] - i[2])
		if i[1] < a:
			time += a - i[1]
			time += abs(i[3] - a)
		elif i[1] > b:
			time += i[1] - b
			time += abs(i[3] - b)
		elif a <= i[1] <= b:
			time += abs(i[1] - i[3])
		print(time)


(n, h, a, b, k) = map(int, input().split())
for qq in range(0, k):
	(ta, fa, tb, fb) = map(int, input().split())
	sum = abs(ta - tb) + abs(fa - fb)
	if ta != tb:
		if fa < a and fb < a:
			sum += 2 * (a - max(fa, fb))
		if fa > b and fb > b:
			sum += 2 * (min(fa, fb) - b)
	print(sum)


(n, m, a, b, k) = map(int, input().split())
asks = list()
for i in range(k):
	asks.append(list(map(int, input().split())))
for ask in asks:
	answer = abs(ask[0] - ask[2])
	if ask[1] < a and ask[3] < a and (ask[0] != ask[2]):
		answer += a - ask[1] + a - ask[3]
	elif ask[1] > b and ask[3] > b and (ask[0] != ask[2]):
		answer += ask[1] - b + ask[3] - b
	else:
		answer += abs(ask[1] - ask[3])
	print(answer)


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, h, a, b, k) = rint()
for i in range(k):
	(ta, fa, tb, fb) = rint()
	ans = 0
	if ta == tb:
		ans = abs(fa - fb)
	elif fa > b:
		ans = fa - b + abs(b - fb) + abs(tb - ta)
	elif fa < a:
		ans = a - fa + abs(a - fb) + abs(tb - ta)
	elif fb > b:
		ans = fb - b + abs(b - fa) + abs(tb - ta)
	elif fb < a:
		ans = a - fb + abs(a - fa) + abs(tb - ta)
	else:
		ans = abs(fa - fb) + abs(tb - ta)
	print(ans)


def check(y, y2, a, b):
	ans = 0
	if y > b:
		ans += y - b
		y = b
	elif y < a:
		ans += a - y
		y = a
	ans += abs(y - y2)
	return ans
(n, h, a, b, k) = input().split()
n = int(n)
h = int(h)
a = int(a)
b = int(b)
k = int(k)
if b < a:
	(a, b) = (b, a)
for i in range(1, int(k) + 1):
	(x1, y1, x2, y2) = input().split()
	ans = 0
	if int(x1) != int(x2):
		ans += check(int(y1), int(y2), int(a), int(b))
	else:
		ans += abs(int(y1) - int(y2))
	ans += abs(int(x1) - int(x2))
	print(ans)


inp = input().split()
n = int(inp[0])
h = int(inp[1])
a = int(inp[2])
b = int(inp[3])
k = int(inp[4])
data = []
for i in range(k):
	inp = input().split()
	ta = int(inp[0])
	fa = int(inp[1])
	tb = int(inp[2])
	fb = int(inp[3])
	if ta == tb:
		print(abs(fa - fb))
	elif fa >= a and fa <= b:
		print(abs(ta - tb) + abs(fa - fb))
	elif fb >= a and fb <= b:
		print(abs(ta - tb) + abs(fa - fb))
	else:
		print(abs(ta - tb) + min(abs(fa - a) + abs(fb - a), abs(fa - b) + abs(fb - b)))


I = lambda : map(int, input().split())
f = abs
(n, _, a, b, k) = I()
while k:
	(p, q, u, v) = I()
	P = [a, b]
	if a <= q <= b:
		P += [q]
	if a <= v <= b:
		P += [v]
	print([min((f(q - x) + f(v - x) for x in P)) + f(p - u), f(q - v)][p == u])
	k -= 1


(n, h, a, b, k) = [int(x) for x in input().split()]
for i in range(k):
	(ta, fa, tb, fb) = [int(x) for x in input().split()]
	if ta == tb:
		print(abs(fa - fb))
		continue
	elif a <= fa <= b:
		print(abs(tb - ta) + abs(fb - fa))
		continue
	else:
		if fa < a:
			tob = a - fa
			fp = a
		else:
			tob = fa - b
			fp = b
		print(tob + abs(tb - ta) + abs(fb - fp))


L = list(map(int, input().split()))
for a in range(L[-1]):
	Q = list(map(int, input().split()))
	s = 0
	if Q[1] >= L[2]:
		if Q[1] <= L[3]:
			s = abs(Q[2] - Q[0]) + abs(Q[3] - Q[1])
		else:
			s = Q[1] - L[3] + abs(Q[2] - Q[0]) + abs(Q[3] - L[3])
	else:
		s = L[2] - Q[1] + abs(Q[2] - Q[0]) + abs(Q[3] - L[2])
	if Q[2] == Q[0]:
		s = abs(Q[1] - Q[3])
	print(s)


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	ans = 0
	x = -1
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fb - fa))
		continue
	if fa < a:
		ans += a - fa
		x = 1
	elif fa > b:
		ans += fa - b
		x = 2
	ans += abs(tb - ta)
	if x == 1:
		ans += abs(a - fb)
	elif x == 2:
		ans += abs(b - fb)
	elif x == -1:
		ans += abs(fb - fa)
	print(ans)


arr = list(map(int, input().split()))
n = arr[0]
h = arr[1]
a = arr[2]
b = arr[3]
for i in range(arr[4]):
	arr1 = list(map(int, input().split()))
	n1 = arr1[0]
	n2 = arr1[2]
	h1 = arr1[1]
	h2 = arr1[3]
	if n1 == n2:
		print(abs(h1 - h2))
	else:
		if h1 > b:
			x = h1 - b
			y = abs(h2 - b)
		elif h1 < a:
			x = a - h1
			y = abs(h2 - a)
		else:
			x = 0
			y = abs(h2 - h1)
		z = abs(n1 - n2)
		print(x + y + z)


(n, h, a, b, k) = [int(j) for j in input().split()]
for i in range(k):
	(t1, f1, t2, f2) = [int(j) for j in input().split()]
	if t1 == t2:
		print(abs(f1 - f2))
	else:
		p = abs(a - f1)
		q = abs(b - f1)
		c = abs(t2 - t1)
		d = abs(f2 - a)
		e = abs(f2 - b)
		if f1 >= b and f2 >= b:
			print(q + abs(t2 - t1) + abs(f2 - b))
		elif f1 <= a and f2 <= a:
			print(p + abs(t2 - t1) + abs(f2 - a))
		elif f1 >= b and f2 <= a:
			print(q + c + e)
		elif f1 >= b and f2 <= b and (f2 >= a):
			print(q + c + e)
		elif f1 <= a and f2 <= b and (f2 >= a):
			print(p + c + d)
		elif f1 <= a and f2 >= b:
			print(p + c + d)
		elif f1 >= a and f1 <= b and (f2 >= b):
			print(q + c + e)
		elif f1 <= b and f1 >= a and (f2 <= a):
			print(p + c + d)
		elif f1 >= a and f1 <= b and (f2 >= a) and (f2 <= b):
			print(c + abs(f1 - f2))


firstline = input().split()
n = int(firstline[0])
h = int(firstline[1])
a = int(firstline[2])
b = int(firstline[3])
k = int(firstline[4])
for i in range(0, k):
	queries = input().split()
	ta = int(queries[0])
	fa = int(queries[1])
	tb = int(queries[2])
	fb = int(queries[3])
	if ta == tb:
		print(abs(fa - fb))
	elif fa > b and fb > b:
		print(abs(ta - tb) + (fa - b) + (fb - b))
	elif fa < a and fb < a:
		print(abs(ta - tb) + (a - fa) + (a - fb))
	else:
		print(abs(ta - tb) + abs(fa - fb))


(n, h, a, b, k) = [int(i) for i in input().split()]
for i in range(k):
	(t1, f1, t2, f2) = [int(j) for j in input().split()]
	if t1 == t2:
		print(str(abs(f1 - f2)))
	elif f1 >= a and f1 <= b:
		print(str(abs(t1 - t2) + abs(f1 - f2)))
	elif f1 < a:
		print(str(abs(t1 - t2) + abs(f1 - a) + abs(f2 - a)))
	else:
		print(str(abs(t1 - t2) + abs(f1 - b) + abs(f2 - b)))


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	ans = 0
	if ta != tb:
		if a <= fa <= b:
			cf = fa
		else:
			if abs(fa - b) > abs(fa - a):
				cf = a
			else:
				cf = b
			ans += abs(cf - fa)
		ans += abs(cf - fb)
		ans += abs(tb - ta)
	else:
		ans = abs(fa - fb)
	print(ans)


import sys
import os

def solve(a, b, t1, f1, t2, f2):
	if t1 == t2:
		return abs(f1 - f2)
	elif f1 >= a and f1 <= b or (f2 >= a and f2 <= b):
		return abs(t1 - t2) + abs(f1 - f2)
	elif f1 > b and f2 > b:
		return abs(t1 - t2) + f1 + f2 - 2 * b
	elif f1 < a and f2 < a:
		return abs(t1 - t2) + 2 * a - f1 - f2
	else:
		return abs(t1 - t2) + abs(f1 - f2)

def main():
	(n, h, a, b, k) = map(int, input().split())
	for i in range(k):
		(t1, f1, t2, f2) = map(int, input().split())
		print(solve(a, b, t1, f1, t2, f2))
main()


(n, tm, r1, r2, k) = map(int, input().split())
a = abs
for i in range(k):
	(s1, t1, s2, t2) = map(int, input().split())
	r = min(a(t1 - r1) + a(t2 - r1), a(t1 - r2) + a(t2 - r2))
	flag = r1 <= t2 <= r2 or r1 <= t1 <= r2
	print(a(t1 - t2) if s1 == s2 else a(s1 - s2) + (r, a(t1 - t2))[flag])


(n, h, a, b, k) = map(int, input().split())
for _ in range(k):
	(t1, f1, t2, f2) = map(int, input().split())
	if t1 == t2:
		print(abs(f1 - f2))
		continue
	ans = abs(t2 - t1)
	c = f1
	if f1 < a:
		ans += a - f1
		c = a
	if f1 > b:
		ans += f1 - b
		c = b
	ans += abs(c - f2)
	print(ans)


IP = lambda : list(map(int, input().split()))
IP = lambda : list(map(int, input().split()))
(n, h, a, b, k) = IP()
for i in range(k):
	(ta, fa, tb, fb) = IP()
	ret = abs(tb - ta)
	if ta == tb:
		print(abs(fa - fb))
		continue
	if a <= fa <= b:
		ret += abs(fa - fb)
	else:
		ret += abs(a - fb) + a - fa if fa < a else abs(b - fb) + fa - b
	print(ret)


X = list(map(int, input().split()))
for i in range(X[-1]):
	Temp = list(map(int, input().split()))
	SUM = 0
	SUM += abs(Temp[0] - Temp[2])
	if Temp[1] not in range(X[2], X[3] + 1) and SUM != 0:
		Nearest = X[2] if abs(X[2] - Temp[1]) <= abs(Temp[1] - X[3]) else X[3]
		print(SUM + abs(Temp[1] - Nearest) + abs(Temp[3] - Nearest))
		continue
	print(SUM + abs(Temp[1] - Temp[3]))


(n, h, a, b, k) = [int(i) for i in input().split()]
for i in range(k):
	(t1, f1, t2, f2) = [int(i) for i in input().split()]
	if t1 != t2:
		ans1 = abs(t1 - t2)
		if f1 < b and f1 > a:
			ans2 = abs(f1 - f2)
		elif f1 >= b:
			ans2 = abs(f1 - b) + abs(f2 - b)
		else:
			ans2 = abs(f1 - a) + abs(f2 - a)
		ans = ans1 + ans2
		print(ans)
	else:
		print(abs(f1 - f2))


x = input()
x = x.split(' ')
c = int(x[4])
a = int(x[2])
b = int(x[3])
for i in range(0, c):
	time = 0
	y = input()
	y = y.split(' ')
	t1 = int(y[0])
	f1 = int(y[1])
	t2 = int(y[2])
	f2 = int(y[3])
	if t1 == t2:
		k = f1 - f2
		if k < 0:
			k = -k
		print(k, end='\n')
	elif t1 == t2 - 1 or t1 == t2 + 1:
		if f1 >= b:
			time = time + f1 - b
			f1 = b
			time += 1
			k = f1 - f2
			if k < 0:
				k = -k
			time += k
			print(time, end='\n')
		elif f1 <= a:
			time = time + a - f1
			f1 = a
			time += 1
			k = f1 - f2
			if k < 0:
				k = -k
			time += k
			print(time, end='\n')
		else:
			time += 1
			k = f1 - f2
			if k < 0:
				k = -k
			time += k
			print(time, end='\n')
	elif f1 >= b:
		time = time + f1 - b
		f1 = b
		k = t1 - t2
		if k < 0:
			k = -k
		time += k
		l = f1 - f2
		if l < 0:
			l = -l
		time += l
		print(time, end='\n')
	elif f1 <= a:
		time = time + a - f1
		f1 = a
		k = t1 - t2
		if k < 0:
			k = -k
		time += k
		l = f1 - f2
		if l < 0:
			l = -l
		time += l
		print(time, end='\n')
	else:
		m = t1 - t2
		if m < 0:
			m = -m
		time += m
		l = f1 - f2
		if l < 0:
			l = -l
		time += l
		print(time, end='\n')


(n, h, a, b, k) = map(int, input().split())
for i in range(k):
	(ta, fa, tb, fb) = map(int, input().split())
	if ta == tb:
		print(abs(fa - fb))
	elif fa > b or fa < a:
		x = abs(a - fa) + abs(tb - ta) + abs(fb - a)
		y = abs(b - fa) + abs(tb - ta) + abs(fb - b)
		print(min(x, y))
	else:
		print(abs(tb - ta) + abs(fb - fa))


(q, w, e, r, t) = map(int, input().split())
a = ''
for i in range(t):
	(z, x, c, v) = map(int, input().split())
	if z == c:
		a += str(abs(x - v)) + '\n'
	elif x < e:
		a += str(abs(z - c) + abs(e - v) + e - x) + '\n'
	elif x > r:
		a += str(abs(z - c) + abs(r - v) + x - r) + '\n'
	else:
		a += str(abs(z - c) + abs(x - v)) + '\n'
print(a)


(n, h, a, b, k) = map(int, input().split())
Q = [None] * k
for i in range(k):
	Q[i] = list(map(int, input().split()))
for i in range(k):
	if Q[i][0] == Q[i][2]:
		print(abs(Q[i][1] - Q[i][3]))
	elif a <= Q[i][1] <= b or a <= Q[i][3] <= b:
		print(abs(Q[i][1] - Q[i][3]) + abs(Q[i][2] - Q[i][0]))
	else:
		k = abs(Q[i][1] - a) + abs(Q[i][3] - a) + abs(Q[i][2] - Q[i][0])
		l = abs(Q[i][1] - b) + abs(Q[i][3] - b) + abs(Q[i][2] - Q[i][0])
		print(min(k, l))


(n, h, a, b, k) = map(int, input().split())
ans = []
while k:
	(ta, fa, tb, fb) = map(int, input().split())
	x = abs(ta - tb)
	if ta != tb:
		if fa < a and fb < a:
			y = abs(a - fa) + abs(a - fb)
		elif fa > b and fb > b:
			y = abs(fa - b) + abs(fb - b)
		else:
			y = abs(fa - fb)
	else:
		y = abs(fa - fb)
	ans.append(str(x + y))
	k = k - 1
print('\n'.join(ans))


def solve(n, h, a, b, k):
	for i in range(k):
		floor_reach = 0
		ans = 0
		(ta, fa, tb, fb) = map(int, input().split())
		if ta == tb and fa == fb:
			print(0)
		else:
			ans = abs(tb - ta)
			if ans == 0:
				ans = abs(fa - fb)
			else:
				if fa > b:
					ans += fa - b
					floor_reach = b
				elif fa < a:
					ans += a - fa
					floor_reach = a
				else:
					floor_reach = fa
				ans += abs(floor_reach - fb)
			print(ans)
(n, h, a, b, k) = map(int, input().split())
solve(n, h, a, b, k)