Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by $n$ sectors, and the outer area is equally divided by $m$ sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. A wall always exists at the 12 o'clock position.

 $0$ 

The inner area's sectors are denoted as $(1,1), (1,2), \dots, (1,n)$ in clockwise direction. The outer area's sectors are denoted as $(2,1), (2,2), \dots, (2,m)$ in the same manner. For a clear understanding, see the example image above.

Amugae wants to know if he can move from one sector to another sector. He has $q$ questions.

For each question, check if he can move between two given sectors.


-----Input-----

The first line contains three integers $n$, $m$ and $q$ ($1 \le n, m \le 10^{18}$, $1 \le q \le 10^4$) — the number of sectors in the inner area, the number of sectors in the outer area and the number of questions.

Each of the next $q$ lines contains four integers $s_x$, $s_y$, $e_x$, $e_y$ ($1 \le s_x, e_x \le 2$; if $s_x = 1$, then $1 \le s_y \le n$, otherwise $1 \le s_y \le m$; constraints on $e_y$ are similar). Amague wants to know if it is possible to move from sector $(s_x, s_y)$ to sector $(e_x, e_y)$.


-----Output-----

For each question, print "YES" if Amugae can move from $(s_x, s_y)$ to $(e_x, e_y)$, and "NO" otherwise.

You can print each letter in any case (upper or lower).


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

Output
YES
NO
YES



-----Note-----

Example is shown on the picture in the statement.

Source: codeforces | Difficulty: MEDIUM
Tags: Number theory

Mathematics


Solutions:
def ceil(x, y):
	if x % y == 0:
		return x // y
	return x // y + 1
from math import gcd
(n, m, q) = map(int, input().split(' '))
inn = n // gcd(n, m)
inm = m // gcd(n, m)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split(' '))
	if n == 1 or m == 1:
		print('YES')
	elif sx != ex:
		if sx == 1:
			if ceil(sy, inn) == ceil(ey, inm):
				print('YES')
			else:
				print('NO')
		elif ceil(ey, inn) == ceil(sy, inm):
			print('YES')
		else:
			print('NO')
	elif sx == 1:
		if ceil(sy, inn) == ceil(ey, inn):
			print('YES')
		else:
			print('NO')
	elif ceil(ey, inm) == ceil(sy, inm):
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a
(n, m, q) = map(int, input().split())
(sx, sy, ex, ey) = (0, 0, 0, 0)
t = gcd(n, m)
ri = n // t
ro = m // t
(s, e) = (0, 0)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		s = (sy - 1) // ri
	else:
		s = (sy - 1) // ro
	if ex == 1:
		e = (ey - 1) // ri
	else:
		e = (ey - 1) // ro
	if s == e:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	while a and b:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b

def f(x, y):
	if x == 1:
		return y // (n // d)
	else:
		return y // (m // d)
(n, m, q) = map(int, input().split())
d = gcd(n, m)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	(a, b) = (f(sx, sy), f(ex, ey))
	if f(sx, sy) == f(ex, ey):
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	while b:
		a %= b
		(a, b) = (b, a)
	return a
(n, m, q) = map(int, input().split(' '))
step = gcd(n, m)
n_step = n // step
m_step = m // step
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split(' '))
	if sx == 1:
		sector_s = (sy - 1) // n_step
	else:
		sector_s = (sy - 1) // m_step
	if ex == 1:
		sector_e = (ey - 1) // n_step
	else:
		sector_e = (ey - 1) // m_step
	if sector_s == sector_e:
		print('YES')
	else:
		print('NO')


from math import gcd

def mcm(a, b):
	return int(a * b / gcd(int(a), int(b)))
(n, m, q) = [int(i) for i in input().split(' ')]
M = mcm(n, m)
(s1, s2) = (M // n, M // m)
M = mcm(s1, s2)
for i in range(q):
	(sx, sy, ex, ey) = [int(i) for i in input().split(' ')]
	(Ns, Ne) = (-1, -1)
	if sx == 1:
		Ns = sy * s1 // M - (sy * s1 % M == 0)
	else:
		Ns = sy * s2 // M - (sy * s2 % M == 0)
	if ex == 1:
		Ne = ey * s1 // M - (ey * s1 % M == 0)
	else:
		Ne = ey * s2 // M - (ey * s2 % M == 0)
	if Ns == Ne:
		print('YES')
	else:
		print('NO')


import sys
input = lambda : sys.stdin.readline().strip()
from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(m, n)
(mg, ng) = (m // g, n // g)
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	if a == 1:
		b = (b - 1) // ng
	else:
		b = (b - 1) // mg
	if c == 1:
		d = (d - 1) // ng
	else:
		d = (d - 1) // mg
	if b == d:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math
from decimal import *
getcontext().prec = 50
(N, M, Q) = [int(x) for x in stdin.readline().split()]

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
gcd = computeGCD(N, M)
div_inner = N // gcd
div_outer = M // gcd
for i in range(Q):
	(sx, sy, ex, ey) = [int(x) for x in stdin.readline().split()]
	sector_s = 0
	sector_e = 0
	if sx == 1:
		b = Decimal(sy) / Decimal(div_inner)
		sector_s = math.ceil(b)
	else:
		b = Decimal(sy) / Decimal(div_outer)
		sector_s = math.ceil(b)
	if ex == 1:
		b = Decimal(ey) / Decimal(div_inner)
		sector_e = math.ceil(b)
	else:
		b = Decimal(ey) / Decimal(div_outer)
		sector_e = math.ceil(b)
	if sector_s == sector_e:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
for i in range(q):
	ans = 0
	(sx, sy, ex, ey) = map(int, input().split())
	sx -= 1
	sy -= 1
	ex -= 1
	ey -= 1
	if sx == 0:
		yy = n // g
	else:
		yy = m // g
	part1 = sy // yy
	if ex == 0:
		yy = n // g
	else:
		yy = m // g
	part2 = ey // yy
	if part1 != part2:
		ans = 1
	print('YNEOS'[ans::2])


def main():
	import sys
	input = sys.stdin.readline

	def gcd(a, b):
		while b:
			(a, b) = (b, a % b)
		return a
	(n, m, q) = map(int, input().split())
	g = gcd(n, m)
	n //= g
	m //= g
	for i in range(q):
		(s, x, t, y) = map(int, input().split())
		x -= 1
		y -= 1
		if s == 1:
			x //= n
		else:
			x //= m
		if t == 1:
			y //= n
		else:
			y //= m
		if x == y:
			print('YES')
		else:
			print('NO')
	return 0
main()


import sys
import math
fin = sys.stdin
a = [int(i) for i in fin.readline().rstrip('\n').split()]
(s1, s2, questions) = (a[0], a[1], a[2])
gcd = math.gcd(s1, s2)
inter1 = s1 // gcd
inter2 = s2 // gcd
for i in range(questions):
	a = [int(i) for i in fin.readline().rstrip('\n').split()]
	if a[0] == 1:
		x = (a[1] - 1) // inter1
	else:
		x = (a[1] - 1) // inter2
	if a[2] == 1:
		y = (a[3] - 1) // inter1
	else:
		y = (a[3] - 1) // inter2
	if x == y:
		print('YES')
	else:
		print('NO')


from sys import stdin

def gcd(a, b):
	while b != 0:
		t = int(a)
		a = int(b)
		b = t % a
	return int(a)

def lcm(a, b):
	return int(a * b / gcd(a, b))
(n, m, q) = map(int, stdin.readline().strip().split())
b = lcm(n, m) // n
a = lcm(n, m) // m
for i in range(q):
	(x, y, x1, y1) = map(int, stdin.readline().strip().split())
	if x == 2:
		w = y // b
		if y % b != 0:
			w += 1
	else:
		w = y // a
		if y % a != 0:
			w += 1
	if x1 == 2:
		w1 = y1 // b
		if y1 % b != 0:
			w1 += 1
	else:
		w1 = y1 // a
		if y1 % a != 0:
			w1 += 1
	if w == w1:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = [int(x) for x in input().split()]
g = math.gcd(n, m)
ds = [None, n // g, m // g]
buf = []
for _ in range(q):
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	s_area = (sy - 1) // ds[sx]
	e_area = (ey - 1) // ds[ex]
	print(['NO', 'YES'][s_area == e_area])


import math

def main():
	(n, m, q) = list(map(lambda x: int(x), input().split(' ')))
	lcm = n * m // math.gcd(n, m)
	(a, b) = (lcm // n, lcm // m)
	l = a * b // math.gcd(a, b)
	for _ in range(q):
		(sx, sy, ex, ey) = list(map(lambda x: int(x), input().split(' ')))
		(sy, ey) = (sy - 1, ey - 1)
		s = sy * a // l if sx == 1 else sy * b // l
		e = ey * a // l if ex == 1 else ey * b // l
		print('YES' if s == e else 'NO')
main()


(n, m, q) = [int(j) for j in input().split()]
l = m
v = n
while v:
	(l, v) = (v, l % v)
h = l
x = int(n / h)
y = int(m / h)
for i in range(q):
	(a, b, c, d) = [int(j) for j in input().split()]
	if a == 1:
		if c == 1:
			if (b - 1) // x == (d - 1) // x:
				print('YES')
			else:
				print('NO')
			continue
	if a == 2:
		if c == 2:
			if (b - 1) // y == (d - 1) // y:
				print('YES')
			else:
				print('NO')
			continue
	if a == 1:
		if c == 2:
			if (b - 1) // x == (d - 1) // y:
				print('YES')
			else:
				print('NO')
			continue
	if a == 2:
		if c == 1:
			if (b - 1) // y == (d - 1) // x:
				print('YES')
			else:
				print('NO')


import math
(n, m, q) = map(int, input().split(' '))
l = n * m // math.gcd(n, m)
for i in range(q):
	(x1, y1, x2, y2) = map(int, input().split(' '))
	f1 = y1 * m
	f2 = y2 * m
	if x1 == 2:
		f1 = y1 * n
	if x2 == 2:
		f2 = y2 * n
	if (f1 - 1) // l != (f2 - 1) // l:
		print('NO')
	else:
		print('YES')


import math

def read():
	return map(int, input().split(' '))
(n, m, q) = read()
lcm = n * m // math.gcd(n, m)
while q:
	(a, b, c, d) = read()
	(ans1, ans2) = (0, 0)
	if a == 1:
		ans1 = b * m
	else:
		ans1 = b * n
	if c == 1:
		ans2 = d * m
	else:
		ans2 = d * n
	flag = (ans1 - 1) // lcm == (ans2 - 1) // lcm
	if flag:
		print('YES')
	else:
		print('NO')
	q -= 1


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

def lcm(a, b):
	return a * b // gcd(a, b)
(n, m, q) = [int(i) for i in input().split()]
lc = lcm(n, m)
nn = lc // n
mm = lc // m
ch = lcm(nn, mm)
for _ in range(q):
	(a, b, c, d) = [int(i) for i in input().split()]
	if a == 1:
		fi = (b - 1) * nn
	else:
		fi = (b - 1) * mm
	if c == 1:
		se = (d - 1) * nn
	else:
		se = (d - 1) * mm
	if fi // ch == se // ch:
		print('YES')
	else:
		print('NO')


import sys
import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
ds = [None, n // g, m // g]
buf = []
for line in sys.stdin:
	(sx, sy, ex, ey) = map(int, line.split())
	s_area = (sy - 1) // ds[sx]
	e_area = (ey - 1) // ds[ex]
	buf.append('yes' if s_area == e_area else 'no')
print('\n'.join(buf))


import math

def solve(sx, sy, ex, ey, n, m, ans):
	if n == m:
		if sy == ey:
			ans.append('YES')
		else:
			ans.append('NO')
	else:
		gcd = math.gcd(max(n, m), min(n, m))
		lcm = n * m // gcd
		blocks1 = lcm // n
		blocks2 = lcm // m
		g_blocks = lcm // gcd
		if sx == 1:
			r1 = [sy * blocks1 - blocks1, sy * blocks1]
		else:
			r1 = [sy * blocks2 - blocks2, sy * blocks2]
		if ex == 1:
			r2 = [ey * blocks1 - blocks1, ey * blocks1]
		else:
			r2 = [ey * blocks2 - blocks2, ey * blocks2]
		x = r1[0] // g_blocks
		g = [g_blocks * x, g_blocks * (x + 1)]
		if r1[0] >= g[0] and r1[1] <= g[1] and (r2[0] >= g[0]) and (r2[1] <= g[1]):
			ans.append('YES')
		else:
			ans.append('NO')

def main():
	ans = []
	(n, m, q) = map(int, input().split())
	for i in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		solve(sx, sy, ex, ey, n, m, ans)
	for i in ans:
		print(i)
main()


from math import gcd
from sys import stdin

def main():
	(n, m, q) = map(int, stdin.readline().split())
	g = gcd(n, m)
	nr = n // g
	mr = m // g
	for _ in range(q):
		(sx, sy, ex, ey) = map(int, stdin.readline().split())
		sr = (sy - 1) // (nr if sx == 1 else mr)
		er = (ey - 1) // (nr if ex == 1 else mr)
		print('YES' if sr == er else 'NO')
main()


(n, m, q) = tuple(map(int, input().split()))

def answer(str1):
	(x_1, x_2, y_1, y_2) = tuple(map(int, str1.split()))
	X = lis[x_1] * x_2
	Y = lis[y_1] * y_2
	if showsec(X) == showsec(Y):
		return 'YES'
	return 'NO'

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b != 0:
		(a, b) = (b, a % b)
	return a

def showsec(X):
	mok = X // larg
	nam = X % larg
	if nam == 0:
		return mok - 1
	return mok
larg = n * m
gd = gcd(n, m)
larg = larg // gd
lis = [0, m, n]
for t in range(q):
	print(answer(input()))


def __gcd(x, y):
	if y == 0:
		return x
	else:
		return __gcd(y, x % y)
(n, m, q) = map(int, input().split())
tmp = __gcd(n, m)
n //= tmp
m //= tmp
lcm = n // __gcd(n, m) * m
x = lcm // m
y = lcm // n
for icase in range(0, q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == ex:
		if sy > ey:
			(sy, ey) = (ey, sy)
		if sx == 1:
			num1 = sy // x * x
			num2 = (sy + x - 1) // x * x
			if sy % x == 0:
				num1 -= x
			if ey <= num2 and ey > num1:
				print('YES')
			else:
				print('NO')
		else:
			num1 = sy // y * y
			num2 = (sy + y - 1) // y * y
			if sy % y == 0:
				num1 -= y
			if ey <= num2 and ey > num1:
				print('YES')
			else:
				print('NO')
	else:
		if sx > ex:
			(sy, ey) = (ey, sy)
		num1 = sy // x * y
		num2 = (sy + x - 1) // x * y
		if sy % x == 0:
			num1 -= y
		num1 = num1
		if ey <= num2 and ey > num1:
			print('YES')
		else:
			print('NO')


import math
(n, m, q) = map(int, input().split(' '))
hsddu = 10923991203912
iusijsaidj = 1829381293
lcm = n * m // math.gcd(n, m)
orz122 = 1029031290321
for i in range(0, q):
	(x1, y1, x2, y2) = map(int, input().split(' '))
	ans1 = int(0)
	orz12192892 = 1029031290320192011
	or8192839z12192892 = 1029031290320192011
	ans2 = int(0)
	orz122918291 = 10010293029031290321
	if x1 == 1:
		ans1 = y1 * m
	else:
		ans1 = y1 * n
	if x2 == 1:
		ans2 = y2 * m
	else:
		ans2 = y2 * n
	if (ans1 - 1) // lcm == (ans2 - 1) // lcm:
		print('YES')
	else:
		print('NO')


def solve(x1, y1, x2, y2):
	if x1 == x2:
		if x1 == 1:
			return (y1 - 1) // n1 == (y2 - 1) // n1
		else:
			return (y1 - 1) // m1 == (y2 - 1) // m1
	elif x1 == 1:
		return (y1 - 1) // n1 == (y2 - 1) // m1
	else:
		return (y1 - 1) // m1 == (y2 - 1) // n1
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
(n, m, q) = map(int, input().split())
k = gcd(n, m)
n1 = n // k
m1 = m // k
res = []
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	res.append('YES' if solve(sx, sy, ex, ey) else 'NO')
print('\n'.join(res))


from fractions import gcd
import math

def myceil(a, b):
	x = a // b
	if a % b == 0:
		return x
	else:
		return x + 1
(n, m, q) = list(map(int, input().split(' ')))
g = gcd(n, m)
for i in range(0, q):
	(sx, sy, ex, ey) = list(map(int, input().split(' ')))
	if sx == 1 and ex == 1:
		if myceil(sy * g, n) == myceil(ey * g, n):
			print('YES')
		else:
			print('NO')
	elif sx == 1 and ex == 2:
		if myceil(sy * g, n) == myceil(ey * g, m):
			print('YES')
		else:
			print('NO')
	elif sx == 2 and ex == 1:
		if myceil(sy * g, m) == myceil(ey * g, n):
			print('YES')
		else:
			print('NO')
	elif sx == 2 and ex == 2:
		if myceil(sy * g, m) == myceil(ey * g, m):
			print('YES')
		else:
			print('NO')


import sys
sys.setrecursionlimit(9999999)

def gcd(a, b):
	while b != 0:
		r = a % b
		a = b
		b = r
	return a
(n, m, q) = map(int, input().split())
a = gcd(n, m)
for _ in range(q):
	(s_x, s_y, e_x, e_y) = map(int, input().split())
	if s_x == 1:
		s_pos = (s_y - 1) // (n // a)
	else:
		s_pos = (s_y - 1) // (m // a)
	if e_x == 1:
		e_pos = (e_y - 1) // (n // a)
	else:
		e_pos = (e_y - 1) // (m // a)
	print('YES' if e_pos == s_pos else 'NO')


def evklid(a, b):
	(a, b) = (max(a, b), min(a, b))
	while b > 0:
		(a, b) = (b, a % b)
	return a
(n, m, q) = map(int, input().split())
d = evklid(n, m)
roomsInSector = [0, n // d, m // d]
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sector_s = (sy - 1) // roomsInSector[sx]
	sector_e = (ey - 1) // roomsInSector[ex]
	if sector_s == sector_e:
		print('YES')
	else:
		print('NO')


import math

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(n, m, q) = map(int, input().split())
b = gcd(n, m)
A = [n // b, m // b]
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if (sy - 1) // A[sx - 1] == (ey - 1) // A[ex - 1]:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
lcm = n * m // gcd(n, m)
out = lcm // n
inn = lcm // m
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	(s1, s2) = (0, 0)
	if sx == 2:
		s1 = (sy - 1) // out
	else:
		s1 = (sy - 1) // inn
	if ex == 2:
		s2 = (ey - 1) // out
	else:
		s2 = (ey - 1) // inn
	if s1 == s2:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
lcm = n * m // g
tam_n = m
tam_m = n
amm_n = lcm // tam_n
amm_m = lcm // tam_m
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	pos_s = None
	sy = sy - 1
	ey = ey - 1
	if sx == 1:
		pos_s = sy // amm_n
	else:
		pos_s = sy // amm_m
	pos_e = None
	if ex == 1:
		pos_e = ey // amm_n
	else:
		pos_e = ey // amm_m
	if pos_e == pos_s:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
l = n * m // gcd(n, m)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		s = (sy - 1) * m
	else:
		s = (sy - 1) * n
	if ex == 1:
		e = (ey - 1) * m
	else:
		e = (ey - 1) * n
	if s < e:
		s += m - 1 if sx == 1 else n - 1
	else:
		e += m - 1 if ex == 1 else n - 1
	if s // l == e // l:
		print('YES')
	else:
		print('NO')


def ev(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
(n, m, q) = map(int, input().split())
k0 = ev(n, m)
k = [n // k0, m // k0]
for i in range(q):
	arr = list(map(int, input().split()))
	q1 = (arr[1] - 1) // k[arr[0] - 1]
	q2 = (arr[3] - 1) // k[arr[2] - 1]
	if q1 == q2:
		print('YES')
	else:
		print('NO')


def main():
	from bisect import bisect_left as bl, bisect_right as br, insort
	import sys, math
	from collections import defaultdict as dd, deque

	def data():
		return sys.stdin.readline().strip()

	def mdata():
		return list(map(int, data().split()))
	out = sys.stdout.write
	INF = float('INF')
	mod = int(1000000000.0) + 7
	(n, m, q) = mdata()
	g = math.gcd(n, m)
	n = n // g
	m = m // g
	for i in range(q):
		(x1, y1, x2, y2) = mdata()
		if x1 == 1:
			a = y1 // n
			if y1 % n == 0:
				a -= 1
		else:
			a = y1 // m
			if y1 % m == 0:
				a -= 1
		if x2 == 1:
			b = y2 // n
			if y2 % n == 0:
				b -= 1
		else:
			b = y2 // m
			if y2 % m == 0:
				b -= 1
		if a == b:
			print('YES')
		else:
			print('NO')
main()


import math
(n, m, q) = map(int, input().split())
d = math.gcd(n, m)
a = (0, n // d, m // d)
for _ in [0] * q:
	(u, x, v, y) = map(int, input().split())
	if (x - 1) // a[u] == (y - 1) // a[v]:
		print('YES')
	else:
		print('NO')


from math import gcd, ceil
gi = lambda : list(map(int, input().split()))

def f(x, y):
	if x % y:
		return x // y + 1
	return x // y
(n, m, q) = gi()
l = [n, m]
g = gcd(n, m)
for k in range(q):
	(x, y, a, b) = gi()
	if f(y, l[x - 1] // g) == f(b, l[a - 1] // g):
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
c1 = n // math.gcd(n, m)
c2 = m // math.gcd(n, m)
for _ in range(q):
	ang1 = 0
	ang2 = 0
	(x, y, x2, y2) = map(int, input().split())
	y -= 1
	y2 -= 1
	if x == 1:
		ang1 = y // c1
	else:
		ang1 = y // c2
	if x2 == 2:
		ang2 = y2 // c2
	else:
		ang2 = y2 // c1
	if ang1 == ang2:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(n, m, q) = list(map(int, input().split()))
h = gcd(n, m)
nh = n // h
mh = m // h
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	if sx == 1:
		sind = (sy - 1) // nh
	else:
		sind = (sy - 1) // mh
	if ex == 1:
		eind = (ey - 1) // nh
	else:
		eind = (ey - 1) // mh
	if sind == eind:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m, q) = input().split(' ')
(n, m, q) = (int(n), int(m), int(q))
g = gcd(n, m)
for i in range(q):
	(ai, a, bi, b) = input().split(' ')
	(ai, a, bi, b) = (int(ai), int(a), int(bi), int(b))
	a = a - 1
	b = b - 1
	(A, B) = (0, 0)
	if ai == 1:
		A = a * g // n
	else:
		A = a * g // m
	if bi == 1:
		B = b * g // n
	else:
		B = b * g // m
	if A == B:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
a = gcd(n, m)
b = n // a
c = m // a
x = []
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		l = (sy - 1) // b
	else:
		l = (sy - 1) // c
	if ex == 1:
		r = (ey - 1) // b
	else:
		r = (ey - 1) // c
	if l == r:
		x.append('YES')
	else:
		x.append('NO')
for i in range(q):
	print(x[i])


def hcf(n, m):
	if n < m:
		(n, m) = (m, n)
	if m == 0:
		return n
	return hcf(n % m, m)

def f(s1, s2):
	if s1 == 1:
		q = s2 // (n // h)
		r = s2 % (n // h)
	else:
		q = s2 // (m // h)
		r = s2 % (m // h)
	return q + (r != 0)
(n, m, q) = map(int, input().strip().split())
h = hcf(n, m)
p = 360 / h
P = [360 / n, 360 / m]
for t in range(q):
	(s1, s2, e1, e2) = map(int, input().strip().split())
	g1 = f(s1, s2)
	g2 = f(e1, e2)
	if g1 != g2:
		print('NO')
	else:
		print('YES')


import math
R = lambda : map(int, input().split())
(n, m, q) = R()
d = math.gcd(n, m)

def compute(x, y):
	y -= 1
	if x == 1:
		return d * y // n
	else:
		return d * y // m
for _ in range(q):
	R = lambda : map(int, input().split())
	(sx, sy, ex, ey) = R()
	if compute(sx, sy) == compute(ex, ey):
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m, q) = [int(x) for x in input().split()]
g = gcd(n, m)
l = n * m // g
for _ in range(q):
	(a, b, c, d) = [int(x) for x in input().split()]
	if a == 1:
		b *= m
	else:
		b *= n
	if c == 1:
		d *= m
	else:
		d *= n
	if (b - 1) // l == (d - 1) // l:
		print('YES')
	else:
		print('NO')


import sys
inp = sys.stdin.read().splitlines()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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

def lastbefore(sy, m, n):
	return (sy * n - 1) // m
(n, m, q) = map(int, inp[0].split())
l = lcm(n, m)
swp = False
if n > m:
	swp = True
	(n, m) = (m, n)
outs = []
for i in range(q):
	(sx, sy, ex, ey) = map(int, inp[i + 1].split())
	if swp:
		sx = 3 - sx
		ex = 3 - ex
	if sx != 1:
		sy = lastbefore(sy, m, n) + 1
	if ex != 1:
		ey = lastbefore(ey, m, n) + 1
	if sy > ey:
		(sy, ey) = (ey, sy)
	if (ey * m - 1) // l >= (sy * m + l - 1) // l:
		outs.append('NO')
	else:
		outs.append('YES')
print('\n'.join(outs))


from math import gcd

def lcm(x, y):
	return x * y // gcd(x, y)
(n, m, q) = map(int, input().split())
units = lcm(n, m)
a = units // n
b = units // m
ss = lcm(a, b)

def loc(x, y):
	if x == 1:
		return 1 + (y * a - 1) // ss
	else:
		return 1 + (y * b - 1) // ss
for qq in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	print('YES' if loc(sx, sy) == loc(ex, ey) else 'NO')


def gcd(a, b):
	while b > 0:
		d = b
		b = a % b
		a = d
	return a
alist = input().split()
n = int(alist[0])
m = int(alist[1])
q = int(alist[2])
nn = m // gcd(n, m)
mm = n // gcd(n, m)
all = mm // gcd(nn, mm) * nn
for i in range(q):
	blist = input().split()
	sx = int(blist[0])
	sy = int(blist[1])
	ex = int(blist[2])
	ey = int(blist[3])
	ju1 = 1
	ju2 = 1
	if sx == 1:
		ju1 = sy * nn
	else:
		ju1 = sy * mm
	if ex == 1:
		ju2 = ey * nn
	else:
		ju2 = ey * mm
	if ju1 - ju1 // all * all == 0:
		ju1 = ju1 // all
	else:
		ju1 = ju1 // all + 1
	if ju2 - ju2 // all * all == 0:
		ju2 = ju2 // all
	else:
		ju2 = ju2 // all + 1
	if ju1 != ju2:
		print('NO')
	else:
		print('YES')


(N, M, Q) = map(int, input().split())

def gcd(n, m):
	if n % m == 0:
		return m
	else:
		return gcd(m, n % m)
lcm = N // gcd(N, M) * M
l = lcm // N // gcd(lcm // N, lcm // M) * (lcm // M)
for q in range(Q):
	(sx, sy, ex, ey) = map(int, input().split())
	s = (sy - 1) * (lcm // N if sx == 1 else lcm // M)
	e = (ey - 1) * (lcm // N if ex == 1 else lcm // M)
	print('YES' if s // l == e // l else 'NO')


import math
(n, m, q) = [int(x) for x in input().split()]
x = math.gcd(n, m)
for i in range(q):
	flag = 0
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	sec1 = int(n / x)
	sec2 = int(m / x)
	if sx == 1:
		if sy % sec1 != 0:
			z = sy // sec1
		else:
			z = sy // sec1 - 1
		if ex == 2:
			if ey % sec2 != 0:
				y = ey // sec2
			else:
				y = ey // sec2 - 1
		elif ey % sec1 != 0:
			y = ey // sec1
		else:
			y = ey // sec1 - 1
		if z == y:
			flag = 1
	elif sx == 2:
		if sy % sec2 != 0:
			z = sy // sec2
		else:
			z = sy // sec2 - 1
		if ex == 1:
			if ey % sec1 != 0:
				y = ey // sec1
			else:
				y = ey // sec1 - 1
		elif ey % sec2 != 0:
			y = ey // sec2
		else:
			y = ey // sec2 - 1
		if z == y:
			flag = 1
	if flag == 1:
		print('YES')
	else:
		print('NO')


from fractions import gcd

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

def divpart(x, y, a, b, l):
	return (y * (a if x == 1 else b) - 1) // l
(n, m, q) = map(int, input().split())
a = lcm(n, m) // n
b = lcm(n, m) // m
l = lcm(a, b)
for ques in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if divpart(sx, sy, a, b, l) == divpart(ex, ey, a, b, l):
		print('YES')
	else:
		print('NO')


from math import gcd as g
(a, b, c) = map(int, input().split())
h = g(a, b)
(g1, g2) = (a // h, b // h)
(j, j1) = (0, 0)
for _ in ' ' * c:
	(x, y, u, v) = map(int, input().split())
	if x == 1:
		j = (y - 1) // g1
	else:
		j = (y - 1) // g2
	if u == 1:
		j1 = (v - 1) // g1
	else:
		j1 = (v - 1) // g2
	print('NYOE S'[j == j1::2])


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(n, m, q) = list(map(int, input().split()))
g = gcd(n, m)
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	if g == 1:
		print('YES')
	else:
		sy -= 1
		ey -= 1
		ks = sy // (n // g) if sx == 1 else sy // (m // g)
		ke = ey // (n // g) if ex == 1 else ey // (m // g)
		if ks == ke:
			print('YES')
		else:
			print('NO')


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : list(map(int, rd().strip().split()))

def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
(n, m, q) = rrd()
g = gcd(n, m)
n = n // g
m = m // g
while q:
	(sx, sy, ex, ey) = rrd()
	sy -= 1
	ey -= 1
	if sx == 1:
		sy = sy // n
	else:
		sy = sy // m
	if ex == 1:
		ey = ey // n
	else:
		ey = ey // m
	if sy == ey:
		print('YES')
	else:
		print('NO')
	q -= 1


import math
(n, m, q) = list(map(int, input().split(' ')))
lcm = n * m // math.gcd(n, m)
for i in range(0, q):
	(x1, y1, x2, y2) = list(map(int, input().split(' ')))
	p1 = int(0)
	p2 = int(0)
	if x1 == 1:
		p1 = y1 * m
	else:
		p1 = y1 * n
	if x2 == 1:
		p2 = y2 * m
	else:
		p2 = y2 * n
	if (p1 - 1) // lcm == (p2 - 1) // lcm:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
d = gcd(n, m)
(x, y) = (n // d, m // d)
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	b = (b - 1) // [x, y][a == 2]
	d = (d - 1) // [x, y][c == 2]
	print('YNEOS'[b != d::2])


import math

def func(x, y):
	return (x - 1) // y
(n, k, q) = map(int, input().split(' '))
gg = n * k // math.gcd(n, k)
t = int(0)
t = 1 * 2
t = 3 * 4
for i in range(0, q):
	(a, b, c, d) = map(int, input().split(' '))
	y = int(0)
	x = int(0)
	if a == 1:
		x = b * k
	else:
		x = b * n
	if c == 1:
		y = d * k
	else:
		y = d * n
	if func(x, gg) == func(y, gg):
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
f = gcd(n, m)
split_n = n // f
split_m = m // f
for x in range(q):
	coords = list(map(int, input().split()))
	if coords[0] == 1:
		section_s = (coords[1] - 1) // split_n
	else:
		section_s = (coords[1] - 1) // split_m
	if coords[2] == 1:
		section_e = (coords[3] - 1) // split_n
	else:
		section_e = (coords[3] - 1) // split_m
	if section_s == section_e:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
d = gcd(n, m)
x = n // d
y = m // d
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	p1 = 0
	p2 = 0
	if sx == 1:
		p1 = (sy - 1) // x
	else:
		p1 = (sy - 1) // y
	if ex == 1:
		p2 = (ey - 1) // x
	else:
		p2 = (ey - 1) // y
	if p1 == p2:
		print('YES')
	else:
		print('NO')


from sys import stdin

def rd():
	return [int(x) for x in stdin.readline().split()]
(N, M, Q) = tuple(rd())

def mapTo1(sy):
	global N
	global M
	global Q
	return sy * N // M

def lnko(a, b):
	if a < b:
		(a, b) = (b, a)
	while b > 0:
		(a, b) = (b, a % b)
	return a
L = lnko(N, M)
NL = N // L
ML = M // L
for q in range(Q):
	(sx, sy, ex, ey) = tuple(rd())
	sy -= 1
	ey -= 1
	if sx == 2:
		sy = mapTo1(sy)
	if ex == 2:
		ey = mapTo1(ey)
	print('YES' if sy // NL == ey // NL else 'NO')


import sys, math
(n, m, q) = map(int, sys.stdin.readline().split())
g = math.gcd(n, m)
for i in range(q):
	(s1x, s1y, s2x, s2y) = map(int, sys.stdin.readline().split())
	if s1x == 1 and s2x == 1:
		if (s1y - 1) // (n // g) == (s2y - 1) // (n // g):
			print('YES')
		else:
			print('NO')
	elif s1x == 1 and s2x == 2:
		if (s1y - 1) // (n // g) == (s2y - 1) // (m // g):
			print('YES')
		else:
			print('NO')
	elif s1x == 2 and s2x == 1:
		if (s2y - 1) // (n // g) == (s1y - 1) // (m // g):
			print('YES')
		else:
			print('NO')
	elif (s1y - 1) // (m // g) == (s2y - 1) // (m // g):
		print('YES')
	else:
		print('NO')


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1
for __ in range(t):
	(n, m, q) = map(int, input().split())
	ng = mt.gcd(n, m)
	g1 = n // ng
	g2 = m // ng
	for _____ in range(q):
		(a, b, c, d) = map(int, input().split())
		b -= 1
		d -= 1
		if a == 1:
			f = b // g1
		else:
			f = b // g2
		if c == 1:
			s = d // g1
		else:
			s = d // g2
		if s == f:
			print('YES')
		else:
			print('NO')


from math import gcd
(n, m, k) = map(int, input().split())
d = gcd(n, m)
x = n // d
y = m // d
l = x * y
for i in range(k):
	(a, b, c, d) = map(int, input().split())
	if a == 1:
		b = b * y
	else:
		b = b * x
	if c == 1:
		d = d * y
	else:
		d = d * x
	if (b - 1) // l == (d - 1) // l:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def gcd(m, n):
	while n != 0:
		t = m % n
		(m, n) = (n, t)
	return abs(m)
(n, m, q) = map(int, input().split())
g = gcd(n, m)
ng = n // g
mg = m // g

def check(z, x):
	global ng, mg
	if z == 1:
		return (x - 1) // ng + 1
	elif z == 2:
		return (x - 1) // mg + 1
for i in range(q):
	(z, x, c, v) = map(int, input().split())
	a = check(z, x)
	b = check(c, v)
	if a == b:
		print('YES')
	else:
		print('NO')


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

def ceil(a, b):
	if a % b == 0:
		return a // b
	return a // b + 1
(n, m, q) = list(map(int, input().split()))
g = gcd(n, m)
f = [n // g, m // g]
for i in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	if ceil(b, f[a - 1]) == ceil(d, f[c - 1]):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

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

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

def getStr():
	return input().strip()

def NOD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b
(N, M, Q) = getVars()
nod = NOD(N, M)
cN = N // nod
cM = M // nod
for _ in range(Q):
	(SX, SY, EX, EY) = getVars()
	SY -= 1
	EY -= 1
	if nod == 1:
		print('YES')
		continue
	if SX == 1:
		sektor1 = SY // cN
	else:
		sektor1 = SY // cM
	if EX == 1:
		sektor2 = EY // cN
	else:
		sektor2 = EY // cM
	if sektor1 == sektor2:
		print('YES')
	else:
		print('NO')


import math
from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())
(n, m, q) = mi()
g = math.gcd(n, m)
l = n // g
h = m // g
for _ in range(q):
	(a, b, x, y) = mi()
	if a == 1:
		p = (b - 1) // l
	else:
		p = (b - 1) // h
	if x == 1:
		s = (y - 1) // l
	else:
		s = (y - 1) // h
	print('YES' if p == s else 'NO')


def gcd(a, b):
	c = min(a, b)
	d = max(a, b)
	gc = c
	while d % gc != 0:
		temp = gc
		gc = d % gc
		d = temp
	return gc
(n, m, q) = map(int, input().split())
h = gcd(n, m)
(e, f) = (n // h, m // h)
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	(b, d) = (b - 1, d - 1)
	if a == 1:
		b = b // e
	else:
		b = b // f
	if c == 1:
		d = d // e
	else:
		d = d // f
	if d == b:
		print('YES')
	else:
		print('NO')


import math

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(inner_sectors, outer_sectors, q) = map(int, input().split())
connectivity_components = gcd(inner_sectors, outer_sectors)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		sec1_cc = (sy - 1) // (inner_sectors // connectivity_components)
	else:
		sec1_cc = (sy - 1) // (outer_sectors // connectivity_components)
	if ex == 1:
		sec2_cc = (ey - 1) // (inner_sectors // connectivity_components)
	else:
		sec2_cc = (ey - 1) // (outer_sectors // connectivity_components)
	if sec1_cc == sec2_cc:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())

def nod(a, b):
	if b == 0:
		return a
	else:
		return nod(b, a % b)

def nok(a, b):
	return a * b // nod(a, b)
x = nok(n, m)
(a, b) = (x // n, x // m)
y = nok(a, b)
(c, d) = (y // a, y // b)

def dist(o, p):
	if o == 1:
		return p * x // n
	else:
		return p * x // m
for i in range(q):
	(o, p, r, s) = map(int, input().split())
	(t, u) = (dist(o, p), dist(r, s))
	(t, u) = (min(t, u), max(t, u))
	if (t - 1) // y + 1 != (u - 1) // y + 1:
		print('NO')
	else:
		print('YES')


import math

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(n, m, q) = map(int, input().split())
g = gcd(n, m)
nd = n // g
md = m // g
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	g1 = (sy - 1) // (nd if sx == 1 else md)
	g2 = (ey - 1) // (nd if ex == 1 else md)
	print('YES' if g1 == g2 else 'NO')


from math import gcd
(n, m, q) = list(map(int, input().split()))
kabe = gcd(n, m)
n //= kabe
m //= kabe
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	sy -= 1
	ey -= 1
	if sx == 1:
		if ex == 1:
			if sy // n == ey // n:
				print('YES')
			else:
				print('NO')
		elif sy // n == ey // m:
			print('YES')
		else:
			print('NO')
	elif ex == 1:
		if sy // m == ey // n:
			print('YES')
		else:
			print('NO')
	elif sy // m == ey // m:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a
(n, m, q) = map(int, input().split())
g = gcd(n, m)
n = n // g
m = m // g
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	a = (sy - 1) // (n if sx == 1 else m)
	b = (ey - 1) // (n if ex == 1 else m)
	print('YES' if a == b else 'NO')


from sys import stdin
input = stdin.readline
from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
a = n // g
b = m // g
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		sy //= a
	else:
		sy //= b
	if ex == 1:
		ey //= a
	else:
		ey //= b
	if sy == ey:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m, q) = [int(s) for s in input().split()]
fi = gcd(n, m)
for qq in range(q):
	(sx, sy, ex, ey) = [int(s) for s in input().split()]
	c = n // fi if sx == 1 else m // fi
	ans1 = (sy - 1) // c
	c = n // fi if ex == 1 else m // fi
	ans2 = (ey - 1) // c
	print('YES' if ans1 == ans2 else 'NO')


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

def greatest(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
(n, m, q) = map(int, input().split(' '))
g = gcd(n, m)
t1 = n // g
t2 = m // g
for i in range(q):
	(a, b, c, d) = map(int, input().split(' '))
	temp1 = 0
	temp2 = 0
	if a == 1:
		temp1 = greatest(b, t1)
	elif a == 2:
		temp1 = greatest(b, t2)
	if c == 1:
		temp2 = greatest(d, t1)
	elif c == 2:
		temp2 = greatest(d, t2)
	if temp1 == temp2:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from collections import *

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)
(n, m, q) = map(int, input().split())
L = lcm(n, m)
N = L // m
M = L // n
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		pos1 = sy // N
	else:
		pos1 = sy // M
	if ex == 1:
		pos2 = ey // N
	else:
		pos2 = ey // M
	if pos1 == pos2:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline
from math import gcd
lcd = lambda a, b: a * b // gcd(a, b)
(n, m, q) = map(int, input().split())
l = lcd(n, m)
disn = l // n
dism = l // m
x = lcd(dism, disn)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		sy *= disn
	else:
		sy *= dism
	if ex == 1:
		ey *= disn
	else:
		ey *= dism
	ey //= x
	sy //= x
	if ey == sy:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
d = math.gcd(n, m)
n1 = n // d
m1 = m // d
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == ex:
		if sx == 1:
			val1 = (sy - 1) // n1
			val2 = (ey - 1) // n1
			if val1 == val2:
				print('YES')
			else:
				print('NO')
		else:
			val1 = (ey - 1) // m1
			val2 = (sy - 1) // m1
			if val1 == val2:
				print('YES')
			else:
				print('NO')
	elif sx == 1:
		val1 = (sy - 1) // n1
		val2 = (ey - 1) // m1
		if val1 == val2:
			print('YES')
		else:
			print('NO')
	else:
		val1 = (ey - 1) // n1
		val2 = (sy - 1) // m1
		if val1 == val2:
			print('YES')
		else:
			print('NO')


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)

def gets(i, s, g):
	return i // (s // g)
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
for _ in range(q):
	(t1, i1, t2, i2) = map(int, input().split())
	if t1 == 1:
		c = gets(i1 - 1, n, g)
	else:
		c = gets(i1 - 1, m, g)
	if t2 == 1:
		d = gets(i2 - 1, n, g)
	else:
		d = gets(i2 - 1, m, g)
	print('YES' if c == d else 'NO')


from math import gcd
(n, m, q) = [int(p) for p in input().split()]
a1 = m // gcd(n, m)
a2 = n // gcd(n, m)
for i in range(q):
	(s1, s2, e1, e2) = [int(p) for p in input().split()]
	s1 -= 1
	s2 -= 1
	e1 -= 1
	e2 -= 1
	if s1 == 1:
		g1 = s2 // a1
	else:
		g1 = s2 // a2
	if e1 == 1:
		g2 = e2 // a1
	else:
		g2 = e2 // a2
	if g1 == g2:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
(s1, s2) = (n // g, m // g)
for i in range(0, q):
	(x1, y1, x2, y2) = [int(s) - 1 for s in input().split()]
	y1 //= s1 if x1 == 0 else s2
	y2 //= s1 if x2 == 0 else s2
	print('YES' if y1 == y2 else 'NO')


import sys
from sys import stdin
import math
(n, m, q) = map(int, stdin.readline().split())
g = n * m // math.gcd(n, m)
ANS = []
for loop in range(q):
	(sx, sy, ex, ey) = map(int, stdin.readline().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		t1 = m * sy
	else:
		t1 = n * sy
	if ex == 1:
		t2 = m * ey
	else:
		t2 = n * ey
	if t1 // g == t2 // g:
		ANS.append('YES')
	else:
		ANS.append('NO')
print('\n'.join(ANS))


(n, m, q) = list(map(int, input().split()))

def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
outer_inner_gcd = gcd(n, m)
line_outer_each = m // outer_inner_gcd
line_inner_each = n // outer_inner_gcd
for _ in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	if sx == 1:
		lines_before_s = (sy - 1) // line_inner_each
	elif sx == 2:
		lines_before_s = (sy - 1) // line_outer_each
	if ex == 1:
		lines_before_e = (ey - 1) // line_inner_each
	elif ex == 2:
		lines_before_e = (ey - 1) // line_outer_each
	if lines_before_e == lines_before_s:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
p = gcd(n, m)
ss = {1: n // p, 2: m // p}
for _ in range(q):
	(a, aa, b, bb) = map(int, input().split())
	s = (aa - 1) // ss[a]
	t = (bb - 1) // ss[b]
	if s == t:
		print('YES')
	else:
		print('NO')


import math
[n, m, case] = map(int, input().split())

def mcd(a, b):
	if a == 0:
		return b
	if b == 0:
		return a
	r = a % b
	return mcd(b, r)

def IsValid(a, b, c, d):
	MCD = mcd(m, n)
	d1 = n // MCD
	d2 = m // MCD
	if a == c:
		if a == 1:
			if (b - 1) // d1 == (d - 1) // d1:
				return 'YES'
		if a == 2:
			if (b - 1) // d2 == (d - 1) // d2:
				return 'YES'
	if a == 1 and c == 2:
		if (b - 1) // d1 == (d - 1) // d2:
			return 'YES'
	if a == 2 and c == 1:
		if (b - 1) // d2 == (d - 1) // d1:
			return 'YES'
	return 'NO'
o = 0
while o < case:
	[a, b, c, d] = map(int, input().split())
	o = o + 1
	print(IsValid(a, b, c, d))


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == ex == 1:
		a = b = n // g
	elif sx == ex == 2:
		a = b = m // g
	elif sx == 1:
		(a, b) = (n // g, m // g)
	else:
		(a, b) = (m // g, n // g)
	print('YES' if (sy - 1) // a == (ey - 1) // b else 'NO')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
(n, m) = (n // g, m // g)
for i in range(q):
	(a1, b1, a2, b2) = map(int, input().split())
	b1 -= 1
	b2 -= 1
	if a1 - 2:
		c1 = b1 // n
	else:
		c1 = b1 // m
	if a2 - 2:
		c2 = b2 // n
	else:
		c2 = b2 // m
	if c1 == c2:
		print('YES')
	else:
		print('NO')


import sys
from math import gcd

def repititions(out_div, in_div):
	com_divr = gcd(out_div, in_div)
	outrep = in_div // com_divr
	inrep = out_div // com_divr
	return (outrep, inrep)

def sectorpath(outrep, inrep):
	(sx, sy, ex, ey) = map(int, sys.stdin.readline().split())
	srep = inrep if sx == 1 else outrep
	erep = inrep if ex == 1 else outrep
	print('Yes' if (sy + srep - 1) // srep == (ey + erep - 1) // erep else 'No')
(out_div, in_div, queries) = map(int, sys.stdin.readline().split())
(outrep, inrep) = repititions(out_div, in_div)
for i in range(queries):
	sectorpath(outrep, inrep)


(i, o, q) = input().split(' ')
(i, o, q) = (int(i), int(o), int(q))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
min = gcd(i, o)
s1 = i // min
s2 = o // min
for que in range(q):
	(r1, t1, r2, t2) = map(lambda x: int(x), input().split(' '))
	t1 -= 1
	t2 -= 1
	if r1 == 1:
		t1 = t1 // s1
	else:
		t1 = t1 // s2
	if r2 == 1:
		t2 = t2 // s1
	else:
		t2 = t2 // s2
	if t1 == t2:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b != 0:
		(a, b) = (b, a % b)
	return a
(n1, m1, q) = map(int, input().split(' '))
hcf = gcd(n1, m1)
n = n1 // hcf
m = m1 // hcf
for ques in range(q):
	(sx, sy, ex, ey) = map(int, input().split(' '))
	sy -= 1
	ey -= 1
	if sx == 1:
		a = sy // n
	else:
		a = sy // m
	if ex == 1:
		b = ey // n
	else:
		b = ey // m
	if a == b:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from math import gcd
input = stdin.readline
(n, m, q) = map(int, input().split())
g = gcd(n, m)
for _ in range(q):
	(s1, s2, e1, e2) = map(int, input().split())
	if s1 == 1:
		k1 = (s2 - 1) * g // n
	else:
		k1 = (s2 - 1) * g // m
	if e1 == 1:
		k2 = (e2 - 1) * g // n
	else:
		k2 = (e2 - 1) * g // m
	print('YES' if k1 == k2 else 'NO')


import math
(n, m, q) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(q)]
gcd = math.gcd(n, m)
kn = n // gcd
km = m // gcd
for i in range(q):
	if a[i][0] == 1:
		x = a[i][1] // kn
		if a[i][1] % kn != 0:
			x += 1
	else:
		x = a[i][1] // km
		if a[i][1] % km != 0:
			x += 1
	if a[i][2] == 1:
		y = a[i][3] // kn
		if a[i][3] % kn != 0:
			y += 1
	else:
		y = a[i][3] // km
		if a[i][3] % km != 0:
			y += 1
	if x == y:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
nmq = input().split()
n = int(nmq[0])
m = int(nmq[1])
q = int(nmq[2])
counted_gcd = gcd(max(n, m), min(n, m))
nod_n = n // counted_gcd
nod_m = m // counted_gcd
for i in range(q):
	se = input().split()
	sx = int(se[0])
	sy = int(se[1]) - 1
	ex = int(se[2])
	ey = int(se[3]) - 1
	if sx == 1:
		if ex == 1:
			if sy // nod_n == ey // nod_n:
				print('YES')
			else:
				print('NO')
		elif sy // nod_n == ey // nod_m:
			print('YES')
		else:
			print('NO')
	elif ex == 1:
		if sy // nod_m == ey // nod_n:
			print('YES')
		else:
			print('NO')
	elif sy // nod_m == ey // nod_m:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = input().split()
n = int(n)
m = int(m)
q = int(q)
gcd = math.gcd(n, m)
lcm = n * m // gcd
block = lcm // gcd
for i in range(q):
	(a, b, c, d) = input().split()
	a = int(a)
	b = int(b)
	pa = 0
	pb = 0
	if a == 1:
		pa = lcm // n * b
	else:
		pa = lcm // m * b
	c = int(c)
	d = int(d)
	if c == 1:
		pb = lcm // n * d
	else:
		pb = lcm // m * d
	if (pa - 1) // block == (pb - 1) // block:
		print('YES')
	else:
		print('NO')


import math

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

def main():
	(n, m, q) = map(int, input().split())
	k = gcd(n, m)
	dn = n // k
	dm = m // k
	for _ in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		gs = dm
		if sx == 1:
			gs = dn
		ge = dm
		if ex == 1:
			ge = dn
		group_s = sy // gs
		if sy % gs != 0:
			group_s += 1
		group_e = ey // ge
		if ey % ge != 0:
			group_e += 1
		if group_s == group_e:
			print('YES')
		else:
			print('NO')
main()


import math
from sys import stdin, stdout
(n, m, q) = stdin.readline().strip().split(' ')
(n, m, q) = (int(n), int(m), int(q))
g = math.gcd(n, m)
ng = n // g
mg = m // g

def mymathceil(x, y):
	t1 = x // y
	t2 = x % y
	if t2 == 0:
		return t1
	else:
		return t1 + 1

def getzone(io, num):
	global ng, mg
	if io == 1:
		return mymathceil(num, ng)
	else:
		return mymathceil(num, mg)
for _ in range(q):
	(sx, sy, ex, ey) = stdin.readline().strip().split(' ')
	(sx, sy, ex, ey) = (int(sx), int(sy), int(ex), int(ey))
	if getzone(sx, sy) == getzone(ex, ey):
		stdout.write('YES\n')
	else:
		stdout.write('NO\n')


from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
(n, m, q) = tuple(map(int, input().split(' ')))
sec_in_size = m // gcd(n, m)
sec_out_size = n // gcd(n, m)
lcm_secs = lcm(sec_in_size, sec_out_size)
while q > 0:
	(sx, sy, ex, ey) = tuple(map(int, input().split(' ')))
	start = sy * sec_in_size if sx == 1 else sy * sec_out_size
	end = ey * sec_in_size if ex == 1 else ey * sec_out_size
	if start > end:
		temp = start
		start = end
		end = temp
	if start != end and (start % lcm_secs == 0 or (start // lcm_secs + 1) * lcm_secs < end):
		print('NO')
	else:
		print('YES')
	q -= 1


import sys
import os
from io import BytesIO, IOBase

def ceil(n, k):
	return n // k + (n % k != 0)

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 prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import gcd
for _ in range(1):
	(n, m, q) = mi()
	for i in range(q):
		(sx, sy, ex, ey) = mi()
		sy -= 1
		ey -= 1
		g = gcd(n, m)
		cnt = {1: n // g, 2: m // g}
		(cnts, cnte) = (sy // cnt[sx], ey // cnt[ex])
		if cnts == cnte:
			print('YES')
		else:
			print('NO')


from sys import setcheckinterval, stdin
setcheckinterval(1000)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
from math import gcd

def Frange(a, b):
	x = a + b - 1
	x //= b
	r = [(x - 1) % g, x % g]
	return r
(n, m, q) = lin()
g = gcd(m, n)
ans = [0, n // g, m // g]
for _ in range(q):
	(sw, sv, dw, dv) = lin()
	d = Frange(dv, ans[dw])
	s = Frange(sv, ans[sw])
	(a, b, c, d) = (*d, *s)
	if a == c and b == d:
		print('YES')
	else:
		print('NO')


import sys

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)
in_file = sys.stdin
(n, m, q) = map(int, in_file.readline().strip().split())
d = gcd(n, m)
n = n // d
m = m // d
for _ in range(q):
	(sx, sy, ex, ey) = map(int, in_file.readline().strip().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		sy = sy // n
	else:
		sy = sy // m
	if ex == 1:
		ey = ey // n
	else:
		ey = ey // m
	if ey == sy:
		print('YES')
	else:
		print('NO')
sys.stdout.flush()


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
(n, m, q) = ri()

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

def lcm(a, b):
	return a * b // gcd(a, b)
length = lcm(n, m)
first = length // n
second = length // m
check = lcm(first, second)

def get(whe, x):
	if whe == 1:
		return ((x - 1) * first, x * first)
	else:
		return ((x - 1) * second, x * second)
for i in range(q):
	(a, b, c, d) = ri()
	aa = get(a, b)
	bb = get(c, d)
	minn = min(*aa)
	maxx = min(*bb)
	if minn // check == maxx // check:
		print('YES')
	else:
		print('NO')


(n, m, q) = input().split()
n = int(n)
m = int(m)
q = int(q)

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
block = n * m // gcd(n, m)
for i in range(q):
	(sx, sy, ex, ey) = input().split()
	sx = int(sx)
	sy = int(sy)
	ex = int(ex)
	ey = int(ey)
	if sx == 1:
		temp1 = sy * m - m
	else:
		temp1 = sy * n - n
	if ex == 1:
		temp2 = ey * m - m
	else:
		temp2 = ey * n - n
	a = temp1 // block
	b = temp2 // block
	if a == b:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
l = n // g * m
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	(s, t) = (0, 0)
	if a == 1:
		s = (b - 1) * m
	else:
		s = (b - 1) * n
	if c == 1:
		t = (d - 1) * m
	else:
		t = (d - 1) * n
	x = s // l
	y = t // l
	print('YES' if x == y else 'NO')


[n, m, q] = [int(item) for item in input().split(' ')]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
g = gcd(n, m)
sn = n // g
sm = m // g
while q:
	q -= 1
	[r1, s1, r2, s2] = [int(item) for item in input().split(' ')]
	if g == 1:
		print('YES')
	else:
		d = sn if r1 == 1 else sm
		e = sn if r2 == 1 else sm
		if (s1 - 1) // d == (s2 - 1) // e:
			print('YES')
		else:
			print('NO')


from math import ceil, gcd
(n, m, k) = map(int, input().split())
g = gcd(n, m)
for i in range(k):
	(a, b, c, d) = map(int, input().split())
	b -= 1
	d -= 1
	ans1 = -1
	ans2 = -1
	if a == 1:
		ans1 = b // (n // g)
	else:
		ans1 = b // (m // g)
	if c == 1:
		ans2 = d // (n // g)
	else:
		ans2 = d // (m // g)
	if ans1 == ans2:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	while b > 0:
		a %= b
		(a, b) = (b, a)
	return a
(n, m, q) = map(int, input().split())
lcm = n * m // gcd(n, m)
lenn = lcm // n
lenm = lcm // m
lcmnm = lenn * lenm // gcd(lenn, lenm)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == ex:
		if sx == 1:
			ln = sy * lenn
			lm = ey * lenn
			if (ln + lcmnm - 1) // lcmnm == (lm + lcmnm - 1) // lcmnm:
				print('YES\n')
			else:
				print('NO\n')
		else:
			ln = sy * lenm
			lm = ey * lenm
			if (ln + lcmnm - 1) // lcmnm == (lm + lcmnm - 1) // lcmnm:
				print('YES\n')
			else:
				print('NO\n')
	elif sx == 1:
		ln = sy * lenn
		lm = ey * lenm
		if (ln + lcmnm - 1) // lcmnm == (lm + lcmnm - 1) // lcmnm:
			print('YES\n')
		else:
			print('NO\n')
	else:
		ln = ey * lenn
		lm = sy * lenm
		if (ln + lcmnm - 1) // lcmnm == (lm + lcmnm - 1) // lcmnm:
			print('YES\n')
		else:
			print('NO\n')


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def main():
	(n, m, q) = rmult_int()
	gcd_nm = math.gcd(n, m)
	n_cnt = int(n / gcd_nm)
	m_cnt = int(m / gcd_nm)
	for i in range(q):
		(sx, sy, ex, ey) = rmult_int()
		possible = True
		if gcd_nm != 1:
			s_1 = None
			if sx == 1:
				s_1 = (sy - 1) // n_cnt
			else:
				s_1 = (sy - 1) // m_cnt
			if ex == 1:
				s_2 = (ey - 1) // n_cnt
			else:
				s_2 = (ey - 1) // m_cnt
			possible = s_1 == s_2
		if possible:
			print('YES')
		else:
			print('NO')
main()


from math import gcd
[n, m, q] = [int(x) for x in input().split()]
g = gcd(n, m)
for i in range(q):
	[s_x, s_y, e_x, e_y] = [int(x) for x in input().split()]
	s_y -= 1
	e_y -= 1
	if s_x == 1:
		sector_s = s_y // (n // g)
	else:
		sector_s = s_y // (m // g)
	if e_x == 1:
		sector_e = e_y // (n // g)
	else:
		sector_e = e_y // (m // g)
	print('YES' if sector_s == sector_e else 'NO')


from fractions import Fraction
(n, m, q) = [int(x) for x in input().split()]
f = Fraction(n, m)
g = Fraction(f.numerator, n)

def bounds(t, div):
	(a, b) = t
	jmp = int(b * div)
	l = (a - 1) // jmp
	u = l + 1
	return (l, u)
for _ in range(q):
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	a = (sy, n) if sx == 1 else (sy, m)
	b = (ey, n) if ex == 1 else (ey, m)
	(la, ua) = bounds(a, g)
	(lb, ub) = bounds(b, g)
	if la == lb and ua == ub:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
(n, m, q) = map(int, input().split())
g = gcd(n, m)
al = n * m // g
xx = al // m
yy = al // n
while q > 0:
	q -= 1
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == 1:
		a1 = (y1 - 1) // xx + 1
	else:
		a1 = (y1 - 1) // yy + 1
	if x2 == 1:
		a2 = (y2 - 1) // xx + 1
	else:
		a2 = (y2 - 1) // yy + 1
	if a1 == a2:
		print('YES')
	else:
		print('NO')


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

def lcm(a, b):
	return a * (b // gcd(a, b))
fi = input()
fi = fi.split(' ')
n = int(fi[0])
m = int(fi[1])
q = int(fi[2])
b = int(lcm(n, m))
Tm = int(b // n)
Tn = int(b // m)
T = [Tn, Tm]
for i in range(q):
	fi = input()
	fi = fi.split(' ')
	s1 = int(fi[0])
	s2 = int(fi[1])
	e1 = int(fi[2])
	e2 = int(fi[3])
	firno = int((s2 - 1) // T[s1 - 1])
	secno = int((e2 - 1) // T[e1 - 1])
	if firno == secno:
		print('YES')
	else:
		print('NO')


from math import gcd

def getBelong(arr: list, id: int, pos: int, Lcm: int) -> int:
	return (pos - 1) * arr[id - 1 ^ 1] // Lcm

def main():
	(n, m, q) = map(int, input().split())
	arr = [n, m]
	Lcm = n // gcd(n, m) * m
	while q:
		q -= 1
		(a, b, c, d) = map(int, input().split())
		print('YES' if getBelong(arr, a, b, Lcm) == getBelong(arr, c, d, Lcm) else 'NO')
main()


import math
(n, m, q) = list(map(int, input().strip().split()))
elementary_blocks = n * m // math.gcd(n, m)
(segment_1, segment_2) = (elementary_blocks // n, elementary_blocks // m)
blocked_segments = segment_1 * segment_2 // math.gcd(segment_1, segment_2)
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().strip().split()))
	start = sy * (segment_1 if sx == 1 else segment_2)
	end = ey * (segment_1 if ex == 1 else segment_2)
	(start, end) = (start - 1, end - 1)
	if start // blocked_segments == end // blocked_segments:
		print('YES')
	else:
		print('NO')


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 [int(i) for i in 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):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
(n, m, q) = mi()
g = math.gcd(n, m)
x = n // g
y = m // g
for _ in range(q):
	(sx, sy, ex, ey) = mi()
	if sx == 1:
		p1 = (sy - 1) // x
	else:
		p1 = (sy - 1) // y
	if ex == 2:
		p2 = (ey - 1) // y
	else:
		p2 = (ey - 1) // x
	if p1 == p2:
		print('YES')
	else:
		print('NO')


def gsd(n, m):
	if n * m == 0:
		return n + m
	if n > m:
		return gsd(n % m, m)
	else:
		return gsd(n, m % n)
(n, m, q) = map(int, input().split())
x = gsd(n, m)
d1 = n // x
d2 = m // x
for z in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		s = sy // d1
	else:
		s = sy // d2
	if ex == 1:
		e = ey // d1
	else:
		e = ey // d2
	if s == e:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

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

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	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 power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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

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

def union(x, y, link, size):
	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

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().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, m, q) = int_array()
g = gcd(n, m)
nn = n // g
mm = m // g
for _ in range(q):
	(a, b, c, d) = int_array()
	b -= 1
	d -= 1
	if a == 1:
		x = b // nn
	else:
		x = b // mm
	if c == 1:
		y = d // nn
	else:
		y = d // mm
	if x == y:
		print('YES')
	else:
		print('NO')


from fractions import gcd
arr = [int(x) for x in input().split()]
t = gcd(arr[0], arr[1])
a = arr[0] // t
b = arr[1] // t
for i in range(arr[2]):
	nums = [int(x) for x in input().split()]
	w = nums[1] - 1
	y = nums[3] - 1
	if nums[0] == 1:
		w = w // a
	else:
		w = w // b
	if nums[2] == 1:
		y = y // a
	else:
		y = y // b
	if w == y:
		print('YES')
	else:
		print('NO')


from sys import *
from math import *
(n, m, q) = map(int, stdin.readline().split())
h = gcd(n, m)
d = [0, n // h, m // h]
for i in range(q):
	(x1, y1, x2, y2) = map(int, stdin.readline().split())
	x = (y1 - 1) // d[x1]
	y = (y2 - 1) // d[x2]
	if x == y:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(n, m, q) = [int(x) for x in input().split()]
N = n * m // gcd(n, m)
(one, two) = (N // m, N // n)
for _ in range(q):
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	if sx == 1:
		sy = (sy - 1) // one
	else:
		sy = (sy - 1) // two
	if ex == 1:
		ey = (ey - 1) // one
	else:
		ey = (ey - 1) // two
	if sy == ey:
		print('YES')
	else:
		print('NO')


import math
a1 = list(map(int, input().split()))
n = a1[0]
m = a1[1]
q = a1[2]
a = []
s = math.gcd(n, m)
n = n // s
m = m // s
for i in range(q):
	a = list(map(int, input().split()))
	x1 = a[0]
	y1 = a[1] - 1
	x2 = a[2]
	y2 = a[3] - 1
	if s == 1:
		print('YES')
	elif x1 == 1 and x2 == 1:
		if y1 // n == y2 // n:
			print('YES')
		else:
			print('NO')
	elif x1 == 1 and x2 == 2:
		if y1 // n == y2 // m:
			print('YES')
		else:
			print('NO')
	elif x1 == 2 and x2 == 1:
		if y1 // m == y2 // n:
			print('YES')
		else:
			print('NO')
	elif x1 == 2 and x2 == 2:
		if y1 // m == y2 // m:
			print('YES')
		else:
			print('NO')


import math
(n, m, q) = map(int, input().split())
d = math.gcd(n, m)
t = [n // d, m // d]
for i in range(q):
	(a, x, b, y) = map(lambda x: int(x) - 1, input().split())
	if x // t[a] == y // t[b]:
		print('YES')
	else:
		print('NO')


import math

def getBelong(id: int, pos: int) -> int:
	global n, m, Lcm
	pos -= 1
	if id == 1:
		return pos * m // Lcm
	return pos * n // Lcm
(n, m, q) = map(int, input().split())
Gcd = math.gcd(n, m)
Lcm = n // Gcd * m
while q:
	q -= 1
	(a, b, c, d) = map(int, input().split())
	print('YES' if getBelong(a, b) == getBelong(c, d) else 'NO')


from fractions import Fraction
from math import gcd
(n, m, q) = list(map(int, input().split()))
if gcd(n, m) > 1:
	x = gcd(n, m)
	for ad in range(q):
		(a, b, c, d) = list(map(int, input().split()))
		if a == 1:
			e = n
		else:
			e = m
		if c == 1:
			f = n
		else:
			f = m
		if True:
			if (b - 1) // (e // x) == (d - 1) // (f // x):
				print('YES')
			else:
				print('NO')
else:
	for i in range(q):
		(a, b, c, d) = list(map(int, input().split()))
		if a == 1:
			e = n
		else:
			e = m
		if c == 1:
			f = n
		else:
			f = m
		if (b - 1) // e > (d - 1) // f:
			print('NO')
		else:
			print('YES')


from decimal import Decimal
from math import ceil

def NOD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b
(inner, outer, test_count) = [int(i) for i in input().split()]
nod = NOD(inner, outer)
step_inner = inner // nod
step_outer = outer // nod
i = [0, 0]
o = [0, 0]
ans = []
for test in range(test_count):
	(i[0], i[1], o[0], o[1]) = [Decimal(i) for i in input().split()]
	if i[0] == o[0]:
		if i[0] == 1:
			i_sector = ceil(i[1] / step_inner)
			o_sector = ceil(o[1] / step_inner)
		else:
			i_sector = ceil(i[1] / step_outer)
			o_sector = ceil(o[1] / step_outer)
	else:
		if i[0] > o[0]:
			i[0] = 1
			o[0] = 2
			t = i[1]
			i[1] = o[1]
			o[1] = t
		i_sector = ceil(i[1] / step_inner)
		o_sector = ceil(o[1] / step_outer)
	if i_sector == o_sector:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


import math
(n, m, t) = map(int, input().split())
gridSize = int(n * m // math.gcd(n, m))
nCell = gridSize // n
mCell = gridSize // m
gg = nCell * mCell // math.gcd(nCell, mCell)
for i in range(t):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		sy *= nCell
	else:
		sy *= mCell
	if ex == 1:
		ey *= nCell
	else:
		ey *= mCell
	if (sy + gg - 1) // gg == (ey + gg - 1) // gg:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
for i in range(q):
	(s_x, s_y, e_x, e_y) = map(int, input().split())
	g = math.gcd(n, m)
	g_1 = n // g
	g_2 = m // g
	if -1 * (-s_y // (g_1 if s_x == 1 else g_2)) == -1 * (-e_y // (g_1 if e_x == 1 else g_2)):
		print('YES')
	else:
		print('NO')


from sys import stdin
from math import ceil

def gcd(a, b):
	if b:
		return gcd(b, a % b)
	else:
		return a

def sno(g, n, y):
	return -(-y // (n // g))
(n, m, q) = map(int, stdin.readline().split())
g = gcd(n, m)
for i in range(q):
	(sx, sy, ex, ey) = map(int, stdin.readline().split())
	(one, two) = (0, 0)
	if sx == 1:
		one = sno(g, n, sy)
	else:
		one = sno(g, m, sy)
	if ex == 1:
		two = sno(g, n, ey)
	else:
		two = sno(g, m, ey)
	if one == two:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
l = n // math.gcd(n, m) * m
g = l // math.gcd(n, m)
for i in range(q):
	(a, b, x, y) = map(int, input().split())
	b -= 1
	y -= 1
	b = l // n * b if a == 1 else l // m * b
	y = l // n * y if x == 1 else l // m * y
	if y // g != b // g:
		print('NO')
	else:
		print('YES')


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

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

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
(n, m, q) = neo()
g = math.gcd(n, m)
a = [n // g, m // g]
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if (sy - 1) // a[sx - 1] == (ey - 1) // a[ex - 1]:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
(n, m, q) = list(map(int, input().split()))
a = gcd(n, m)
for _ in range(q):
	(a1, a2, a3, a4) = list(map(int, input().split()))
	if a1 == 1:
		a1 = n // a
	elif a1 == 2:
		a1 = m // a
	if a3 == 1:
		a3 = n // a
	elif a3 == 2:
		a3 = m // a
	if (a2 - 1) // a1 == (a4 - 1) // a3:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
w = gcd(n, m)
np = n // w
mp = m // w
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sp = (sy - 1) // (np if sx == 1 else mp)
	ep = (ey - 1) // (np if ex == 1 else mp)
	if sp == ep:
		print('yes')
	else:
		print('no')


def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
a = input()
(n, m, q) = a.split(' ')
n = int(n)
m = int(m)
q = int(q)
k = gcd(360 * n, 360 * m)
lc = 360 * 360 * n * m / k
lc = int(lc)
while q > 0:
	q -= 1
	s = input()
	(t1, v1, t2, v2) = s.split(' ')
	t1 = int(t1)
	t2 = int(t2)
	v1 = int(v1)
	v2 = int(v2)
	v1 = v1 - 1
	v2 = v2 - 1
	if t1 == t2:
		if t1 == 1:
			x = 360 * m * v1 // lc
			y = 360 * m * v2 // lc
			if x == y:
				print('YES')
			else:
				print('NO')
		else:
			x = 360 * n * v1 // lc
			y = 360 * n * v2 // lc
			if x == y:
				print('YES')
			else:
				print('NO')
	elif t1 == 2:
		x = v1
		v1 = v2
		v2 = x
		x = 360 * m * v1
		y = 360 * n * v2
		x //= lc
		y //= lc
		if x == y:
			print('YES')
		else:
			print('NO')
	else:
		x = 360 * m * v1
		y = 360 * n * v2
		x //= lc
		y //= lc
		if x == y:
			print('YES')
		else:
			print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
(sn, sm) = (n // g, m // g)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		t1 = (sy - 1) // sn
	else:
		t1 = (sy - 1) // sm
	if ex == 1:
		t2 = (ey - 1) // sn
	else:
		t2 = (ey - 1) // sm
	print('YES' if t1 == t2 else 'NO')


import sys

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

def check(t, k):
	if t == 1:
		return g * (k - 1) // N
	return g * (k - 1) // M
(N, M, Q) = map(int, input().split())
g = gcd(N, M)
for _ in range(Q):
	(sx, sy, ex, ey) = map(int, sys.stdin.readline().split())
	if check(sx, sy) == check(ex, ey):
		sys.stdout.write('YES\n')
	else:
		sys.stdout.write('NO\n')


from math import *
(n, m, q) = map(int, input().split())
l = n * m // gcd(n, m)
nf = l // n
mf = l // m
barr = nf * mf // gcd(nf, mf)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sp = (nf if sx == 1 else mf) * (sy - 1)
	ep = (nf if ex == 1 else mf) * (ey - 1)
	start = min(sp, ep)
	end = max(sp, ep)
	barrier = start // barr * barr
	if barrier + barr <= end:
		print('NO')
	else:
		print('YES')


from math import ceil

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

def lcm(a, b):
	return a * b // gcd(a, b)
[n, m, q] = [int(i) for i in input().split()]
l = lcm(n, m)
a = l // m
b = l // n
g = lcm(a, b)
x = g // b
y = g // a
for i in range(q):
	[sx, sy, ex, ey] = [int(i) for i in input().split()]
	sy -= 1
	ey -= 1
	if sx == 1:
		bx = sy // x
	else:
		bx = sy // y
	if ex == 2:
		by = ey // y
	else:
		by = ey // x
	if bx == by:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())

def gcd(x, y):
	if y:
		return gcd(y, x % y)
	return x
g = gcd(n, m)
x = n // g
y = m // g
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	i = (b - 1) // (y if a > 1 else x)
	j = (d - 1) // (y if c > 1 else x)
	print('YES' if i == j else 'NO')


import math
(n, m, q) = map(int, input().split())
nmgcd = math.gcd(n, m)
ns = n // nmgcd
ms = m // nmgcd
x2s = [0, ns, ms]
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if (sy - 1) // x2s[sx] == (ey - 1) // x2s[ex]:
		print('YES')
	else:
		print('NO')


(N, M, Q) = map(int, input().split())
from math import gcd
g = gcd(N, M)
(n, m) = (N // g, M // g)
for _ in range(Q):
	(sx, sy, ex, ey) = map(int, input().split())
	(sy, ey) = (sy - 1, ey - 1)
	s = sy // n if sx == 1 else sy // m
	e = ey // n if ex == 1 else ey // m
	print('YES' if s == e else 'NO')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
i = n // g
o = m // g
for j in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		a = (sy - 1) // i
	else:
		a = (sy - 1) // o
	if ex == 1:
		b = (ey - 1) // i
	else:
		b = (ey - 1) // o
	if a == b:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
gcd = computeGCD(n, m)
group = [0, n // gcd, m // gcd]
flag = True
for i in range(0, q):
	(sx, sy, ex, ey) = map(int, input().split())
	if (sy - 1) // group[sx] == (ey - 1) // group[ex]:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
ng = n // g
mg = m // g
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	sec1 = sy // ng if sx == 1 else sy // mg
	sec2 = ey // ng if ex == 1 else ey // mg
	print('YES' if sec1 == sec2 else 'NO')


def hcf(a, b):
	if a % b == 0:
		return b
	else:
		temp = a
		a = b
		b = temp % b
		return hcf(a, b)
(n, m, q) = map(int, input().rstrip().split())
h = hcf(n, m)
a = [n // h, m // h]
for Q in range(q):
	(s1, s2, e1, e2) = map(int, input().rstrip().split())
	s2 -= 1
	e2 -= 1
	if s2 // a[s1 - 1] == e2 // a[e1 - 1]:
		print('YES')
	else:
		print('NO')


import math
R = lambda : map(int, input().split())
(n, m, q) = R()
d = math.gcd(n, m)
a = (0, n // d, m // d)
for _ in [0] * q:
	(u, x, v, y) = R()
	print('YNEOS'[(x - 1) // a[u] != (y - 1) // a[v]::2])


from fractions import gcd
(n, m, q) = map(int, input().split())
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	g = gcd(n, m)
	if sx == 1:
		ans1 = sy // (n // g) - (sy % (n // g) == 0)
	else:
		ans1 = sy // (m // g) - (sy % (m // g) == 0)
	if ex == 1:
		ans2 = ey // (n // g) - (ey % (n // g) == 0)
	else:
		ans2 = ey // (m // g) - (ey % (m // g) == 0)
	print('YES' if ans1 == ans2 else 'NO')


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

def main():
	(n, m, q) = map(int, input().split())
	d = math.gcd(n, m)
	fn = n // d
	fm = m // d

	def section(a, b):
		return b // fn if a == 1 else b // fm
	for _ in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		print('YES' if section(sx, sy - 1) == section(ex, ey - 1) else 'NO')
main()


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

def main():
	(n, m, q) = map(int, input().split())
	nm = gcd(n, m)
	(ndiv, mdiv) = (n // nm, m // nm)
	for _ in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		if sx == 1 and ex == 1:
			if (sy - 1) // ndiv == (ey - 1) // ndiv:
				print('YES')
			else:
				print('NO')
		elif sx == 2 and ex == 2:
			if (sy - 1) // mdiv == (ey - 1) // mdiv:
				print('YES')
			else:
				print('NO')
		elif sx == 1 and ex == 2:
			if (sy - 1) // ndiv == (ey - 1) // mdiv:
				print('YES')
			else:
				print('NO')
		elif (sy - 1) // mdiv == (ey - 1) // ndiv:
			print('YES')
		else:
			print('NO')
main()


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
lst = input().split()
(n, m, q) = (int(lst[0]), int(lst[1]), int(lst[2]))
g = gcd(n, m)
inSize = n // g
ouSize = m // g
for i in range(1, q + 1):
	lst = input().split()
	(sx, sy, ex, ey) = (int(lst[0]), int(lst[1]), int(lst[2]), int(lst[3]))
	sy = sy - 1
	ey = ey - 1
	if sx == 1:
		sy = sy // inSize
	else:
		sy = sy // ouSize
	if ex == 1:
		ey = ey // inSize
	else:
		ey = ey // ouSize
	if sy == ey:
		print('YES')
	else:
		print('NO')


from math import gcd

def lcm(a, b):
	return a // gcd(a, b) * b
(n, m, q) = map(int, input().split())
total_length = lcm(n, m)
inner_length = total_length // n
outer_length = total_length // m
circle = lcm(inner_length, outer_length)
while q > 0:
	(ff, fs, sf, ss) = map(int, input().split())
	pos_of_first = 0
	pos_of_second = 0
	if ff == 1:
		pos_of_first = fs * inner_length
	else:
		pos_of_first = fs * outer_length
	if sf == 1:
		pos_of_second = ss * inner_length
	else:
		pos_of_second = ss * outer_length
	if pos_of_first // circle + (pos_of_first % circle != 0) == pos_of_second // circle + (pos_of_second % circle != 0):
		print('YES')
	else:
		print('NO')
	q -= 1


def gcd(m, n):
	if m % n == 0:
		return n
	else:
		return gcd(n, m % n)
(n, m, q) = tuple(map(int, input().split()))
for i in range(q):
	(sx, sy, ex, ey) = tuple(map(int, input().split()))
	if sx == 1:
		sx = n
	else:
		sx = m
	if ex == 1:
		ex = n
	else:
		ex = m
	r = gcd(m, n)
	if (sy - 1) // (sx // r) == (ey - 1) // (ex // r):
		print('YES')
	else:
		print('NO')


def gcd(x, y):
	while x > 0 and y > 0:
		x %= y
		(x, y) = (y, x)
	return x + y
(n, m, q) = map(int, input().split())
g = gcd(n, m)
n //= g
m //= g
for _ in range(q):
	(a1, a2, a3, a4) = map(int, input().split())
	a2 -= 1
	a4 -= 1
	if a1 == 1:
		a2 //= n
	else:
		a2 //= m
	if a3 == 1:
		a4 //= n
	else:
		a4 //= m
	if a2 == a4:
		print('YES')
	else:
		print('NO')


from fractions import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
nb = n // g
mb = m // g
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	s = 0
	if sx == 1:
		s = (sy + nb - 1) // nb
	else:
		s = (sy + mb - 1) // mb
	e = 0
	if ex == 1:
		e = (ey + nb - 1) // nb
	else:
		e = (ey + mb - 1) // mb
	print('YES' if s == e else 'NO')


from fractions import gcd
(n, m, q) = map(int, input().split())
key = gcd(n, m)

def zone(x, y):
	if x == 1:
		p = n // key
	else:
		p = m // key
	ok = 0
	ng = key + 1
	while abs(ng - ok) > 1:
		middle = (ng + ok) // 2
		if p * middle < y:
			ok = middle
		else:
			ng = middle
	return ok
if key > max(n, m):
	for _ in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		print('YES')
else:
	for _ in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		l = zone(sx, sy)
		r = zone(ex, ey)
		if l == r:
			print('YES')
		else:
			print('NO')


from math import gcd
(n, m, q) = [int(i) for i in input().split()]
c = [0] * 3
x = gcd(n, m)
(c[1], c[2]) = (n // x, m // x)
for i in range(q):
	(s_x, s_y, e_x, e_y) = [int(j) for j in input().split()]
	j = s_y // c[s_x]
	if s_y % c[s_x] == 0:
		j -= 1
	k = e_y // c[e_x]
	if e_y % c[e_x] == 0:
		k -= 1
	if j == k:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
GCD = gcd(n, m)
LCM = n * m // GCD
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	sy *= GCD
	ey *= GCD
	if sx == 1:
		sy //= n
	else:
		sy //= m
	if ex == 1:
		ey //= n
	else:
		ey //= m
	if sy == ey:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = [int(x) for x in input().split()]
lcm = n // gcd(n, m) * m
for _ in range(q):
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	if sx == 2:
		sy *= n
	else:
		sy *= m
	if ex == 1:
		ey *= m
	else:
		ey *= n
	if (sy - 1) // lcm == (ey - 1) // lcm:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
a = n // g
b = m // g
while q > 0:
	(sx, sy, ex, ey) = map(int, input().split())
	f = 0
	if sx == 1:
		if ex == 1:
			if (sy - 1) // a == (ey - 1) // a:
				f = 1
		elif (sy - 1) // a == (ey - 1) // b:
			f = 1
	elif ex == 1:
		if (sy - 1) // b == (ey - 1) // a:
			f = 1
	elif (sy - 1) // b == (ey - 1) // b:
		f = 1
	if f:
		print('YES')
	else:
		print('NO')
	q = q - 1


import math
(a, b, c) = map(int, input().split())

def m_gcd(x, y):
	if y == 0:
		return x
	else:
		return m_gcd(y, x % y)
gcd = m_gcd(a, b)
a //= gcd
b //= gcd
for i in range(c):
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == 1:
		p1 = (y1 + a - 1) // a
	else:
		p1 = (y1 + b - 1) // b
	if x2 == 1:
		p2 = (y2 + a - 1) // a
	else:
		p2 = (y2 + b - 1) // b
	print('YES' if p1 == p2 else 'NO')


(n, m, q) = (int(i) for i in input().split())

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
g = gcd(n, m)
if g == 1:
	for i in range(q):
		(sx, sy, ex, ey) = (int(j) for j in input().split())
		print('YES')
else:
	wn = n // g
	wm = m // g
	for i in range(q):
		ans = 'YES'
		(sx, sy, ex, ey) = (int(j) for j in input().split())
		if sx == 1:
			if sy % wn == 0:
				sy = sy // wn * wm
			else:
				sy = sy // wn * wm + 1
		if ex == 1:
			if ey % wn == 0:
				ey = ey // wn * wm
			else:
				ey = ey // wn * wm + 1
		if ey > sy:
			(sy, ey) = (ey, sy)
		if (sy - ey) // wm > 0:
			ans = 'NO'
		wall = sy // wm * wm
		if ey <= wall < sy:
			ans = 'NO'
		print(ans)


(n, m, q) = map(int, input().split())
s = []
for i in range(q):
	s.append(list(map(int, input().split())))

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

def lcm(a, b):
	return a // gcd(a, b) * b
g = lcm(n, m)
(a, b) = (g // m, g // n)
for i in s:
	(s1, e1, s2, e2) = i
	if s1 == 1:
		sa = e1
		x1 = a
	else:
		sa = e1
		x1 = b
	if s2 == 1:
		sb = e2
		x2 = a
	else:
		sb = e2
		x2 = b
	xa = sa // x1
	if sa % x1 == 0:
		xa -= 1
	xb = sb // x2
	if sb % x2 == 0:
		xb -= 1
	if xa == xb:
		print('YES')
	else:
		print('NO')


import math
(n, m, k) = map(int, input().split(' '))
gc = math.gcd(n, m)
n = n // gc
m = m // gc
while k > 0:
	k = k - 1
	(x1, y1, x2, y2) = map(int, input().split(' '))
	y1 = y1 - 1
	y2 = y2 - 1
	if x1 == 1:
		y1 = y1 // n
	else:
		y1 = y1 // m
	if x2 == 1:
		y2 = y2 // n
	else:
		y2 = y2 // m
	if y1 == y2:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
for qq in range(q):
	(a, b, c, d) = map(int, input().split())
	if a == 1:
		x = (b - 1) // (n // g)
	else:
		x = (b - 1) // (m // g)
	if c == 1:
		y = (d - 1) // (n // g)
	else:
		y = (d - 1) // (m // g)
	if x == y:
		print('YES')
	else:
		print('NO')


import re
from collections import deque
from functools import reduce
from heapq import *
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep

def gcd(a: int, b: int) -> int:
	(a, b) = (max([a, b]), min([a, b]))
	if b == 0:
		return a
	return gcd(b, a % b)

def fmatr(matrix, lnsep: str=linesep, fieldsep: str=' ') -> str:
	return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))

def fbool(boolval: int) -> str:
	return ['No', 'Yes'][boolval]

def solve() -> None:
	(n, m, q, *t) = map(int, open(0).read().split())
	ans = [None] * q
	walls = gcd(n, m)
	nmult = n // walls
	mmult = m // walls
	dv = n * mmult // walls
	for i in range(q):
		(sx, sy, ex, ey) = (t[4 * i + 0], t[4 * i + 1] - 1, t[4 * i + 2], t[4 * i + 3] - 1)
		syStd = sy * mmult if sx == 1 else sy * nmult
		eyStd = ey * mmult if ex == 1 else ey * nmult
		ans[i] = syStd // dv == eyStd // dv
	print(linesep.join(map(lambda bl: fbool(bl).upper(), ans)))
solve()


def nod(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
(n, m, q) = map(int, input().split())
sectors = n * m // nod(n, m)
(v1, v2) = (sectors // n, sectors // m)
vv = v1 * v2 // nod(v1, v2)
for i in range(q):
	(par1, x, par2, y) = map(int, input().split())
	if par1 == 1:
		x = (x - 1) * v1
	elif par1 == 2:
		x = (x - 1) * v2
	if par2 == 1:
		y = (y - 1) * v1
	elif par2 == 2:
		y = (y - 1) * v2
	if x // vv == y // vv:
		print('YES')
	else:
		print('NO')


import math

def lcm_of(a: int, b: int) -> int:
	return a * b // math.gcd(a, b)

def convert_to_abs(x: int, y: int):
	if x == 1:
		return y * fact_N
	else:
		return y * fact_M
(N, M, Q) = list(map(int, input().split()))
lcm = lcm_of(N, M)
fact_N = lcm // N
fact_M = lcm // M
period = lcm_of(fact_N, fact_M)
for i in range(Q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	sy = convert_to_abs(sx, sy - 1)
	ey = convert_to_abs(ex, ey - 1)
	if sy // period == ey // period:
		print('YES')
	else:
		print('NO')


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

def main():
	line = input().split()
	n = int(line[0])
	m = int(line[1])
	q = int(line[2])
	g = gcd(n, m)
	while q > 0:
		q -= 1
		line = input().split()
		xo = int(line[0])
		yo = int(line[1])
		xi = int(line[2])
		yi = int(line[3])
		yo -= 1
		yi -= 1
		g1 = -1
		g2 = -1
		if xo == 1:
			g1 = yo // (n // g)
		else:
			g1 = yo // (m // g)
		if xi == 1:
			g2 = yi // (n // g)
		else:
			g2 = yi // (m // g)
		if g1 == g2:
			print('YES')
		else:
			print('NO')
main()


def nod(a, b):
	while b != 0:
		c = a % b
		a = b
		b = c
	return a

def nok(a, b):
	return a * b // nod(a, b)
(n, m, q) = map(int, input().split())
a = nok(n, m)
b = nok(a // n, a // m)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sp = 0
	fp = 0
	if sx == 1:
		sp = a // n * sy
	else:
		sp = a // m * sy
	if ex == 1:
		fp = a // n * ey
	else:
		fp = a // m * ey
	if sp % b == 0:
		ssp = sp // b
	else:
		ssp = sp // b + 1
	if fp % b == 0:
		sfp = fp // b
	else:
		sfp = fp // b + 1
	if ssp == sfp:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())

def gcd(a, b):
	while a != 0:
		(a, b) = (b % a, a)
	return b
g = gcd(n, m)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if g == 1:
		print('YES')
	else:
		if sx == 1:
			sy = (sy - 1) // (n // g)
		else:
			sy = (sy - 1) // (m // g)
		if ex == 1:
			ey = (ey - 1) // (n // g)
		else:
			ey = (ey - 1) // (m // g)
		if sy == ey:
			print('YES')
		else:
			print('NO')


from math import *

def gcd(a, b):
	if b == 0:
		return a
	if a < b:
		(a, b) = (b, a)
	return gcd(b, a % b)
(n, m, q) = map(int, input().split())
nok = n * m // gcd(n, m)
d1 = nok // m
d2 = nok // n
for i in range(q):
	(x1, y1, x2, y2) = map(int, input().split())
	k1 = 0
	k2 = 0
	if x1 == 1:
		k1 = max(y1 - 1, 0) // d1
	else:
		k1 = max(y1 - 1, 0) // d2
	if x2 == 1:
		k2 = max(y2 - 1, 0) // d1
	else:
		k2 = max(y2 - 1, 0) // d2
	if k1 == k2:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
l = [n // g, m // g]
res = []
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	x = (b - 1) // l[a - 1]
	y = (d - 1) // l[c - 1]
	res.append('YES' if x == y else 'NO')
print(*res, sep='\n')


from math import gcd

def ceil(a, b):
	return int((a + b - 1) // b)
(n, m, q) = map(int, input().split())
for _ in range(q):
	(a1, b1, a2, b2) = map(int, input().split())
	X = gcd(n, m)
	Hathyar1 = int(n // X)
	Hathyar2 = int(m // X)
	if n == m == 1:
		print('YES')
		continue
	if n == m:
		if b1 == b2:
			print('YES')
		else:
			print('NO')
		continue
	if a1 == a2 == 1:
		Quarter1 = ceil(b1, Hathyar1)
		Quarter2 = ceil(b2, Hathyar1)
		if Quarter1 == Quarter2:
			print('YES')
		else:
			print('NO')
	elif a1 == a2 == 2:
		Quarter1 = ceil(b1, Hathyar2)
		Quarter2 = ceil(b2, Hathyar2)
		if Quarter1 == Quarter2:
			print('YES')
		else:
			print('NO')
	elif a1 == 1 and a2 == 2:
		Quarter1 = ceil(b1, Hathyar1)
		Quarter2 = ceil(b2, Hathyar2)
		if Quarter1 == Quarter2:
			print('YES')
		else:
			print('NO')
	elif a1 == 2 and a2 == 1:
		Quarter1 = ceil(b1, Hathyar2)
		Quarter2 = ceil(b2, Hathyar1)
		if Quarter1 == Quarter2:
			print('YES')
		else:
			print('NO')


import math
(n, m, q) = [int(x) for x in input().split()]
g = math.gcd(n, m)
for te in range(q):
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	if sx == 1:
		ans1 = (sy - 1) * g // n
	elif sx == 2:
		ans1 = (sy - 1) * g // m
	if ex == 1:
		ans2 = (ey - 1) * g // n
	elif ex == 2:
		ans2 = (ey - 1) * g // m
	if ans1 == ans2:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())
from math import gcd, ceil
g = gcd(n, m)
gn = n // g
gm = m // g

def ceil(x, y):
	if x % y == 0:
		return x // y
	return x // y + 1
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	i = j = 0
	if sx == 1:
		i = ceil(sy, gn)
	else:
		i = ceil(sy, gm)
	if ex == 1:
		j = ceil(ey, gn)
	else:
		j = ceil(ey, gm)
	print('YES' if i == j else 'NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
for i in range(q):
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == 1 and x2 == 1:
		l = n // g
		if (y1 - 1) // l == (y2 - 1) // l:
			print('YES')
		else:
			print('NO')
	elif x1 == 2 and x2 == 2:
		l = m // g
		if (y1 - 1) // l == (y2 - 1) // l:
			print('YES')
		else:
			print('NO')
	elif x1 == 1 and x2 == 2:
		l = n // g
		p = m // g
		if (y1 - 1) // l == (y2 - 1) // p:
			print('YES')
		else:
			print('NO')
	else:
		l = n // g
		p = m // g
		if (y1 - 1) // p == (y2 - 1) // l:
			print('YES')
		else:
			print('NO')


import math
(n, m, query) = map(int, input().split())
g = math.gcd(n, m)
(ng, mg) = (n // g, m // g)
for q in range(query):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		sy = (sy - 1) // ng
	else:
		sy = (sy - 1) // mg
	if ex == 1:
		ey = (ey - 1) // ng
	else:
		ey = (ey - 1) // mg
	if sy == ey:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	n2 = n // math.gcd(n, m)
	m2 = m // math.gcd(n, m)
	if sx == 1:
		s1 = (sy - 1) // n2
	else:
		s1 = (sy - 1) // m2
	if ex == 1:
		s2 = (ey - 1) // n2
	else:
		s2 = (ey - 1) // m2
	if s1 == s2:
		print('YES')
	else:
		print('NO')


import math
data = input().split(' ')
n = int(data[0])
m = int(data[1])
q = int(data[2])
nod = math.gcd(n, m)
a = n // nod
b = m // nod
for i in range(q):
	data = input().split(' ')
	sector1 = (int(data[0]), int(data[1]))
	sector2 = (int(data[2]), int(data[3]))
	number1 = (sector1[1] - 1) // a if sector1[0] == 1 else (sector1[1] - 1) // b
	number2 = (sector2[1] - 1) // a if sector2[0] == 1 else (sector2[1] - 1) // b
	if number1 == number2:
		print('YES')
	else:
		print('NO')


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
(n, m, q) = [int(x) for x in inp().split()]
for _ in range(q):
	(a1, s1, a2, s2) = [int(x) for x in inp().split()]
	s1 -= 1
	s2 -= 1
	if a1 == 1:
		s1 //= n // math.gcd(n, m)
	else:
		s1 //= m // math.gcd(n, m)
	if a2 == 1:
		s2 //= n // math.gcd(n, m)
	else:
		s2 //= m // math.gcd(n, m)
	if s1 == s2:
		print('YES')
	else:
		print('NO')


import sys
import os
from io import IOBase, BytesIO
from math import gcd, ceil

def main():
	(n, m, q) = get_ints()
	g = gcd(n, m)
	x = n // g
	y = m // g
	for tc in range(q):
		(sx, sy, ex, ey) = get_ints()
		sy -= 1
		ey -= 1
		if sx == 1 and ex == 1:
			if sy // x == ey // x:
				print('YES')
			else:
				print('NO')
		elif sx == 1 and ex == 2:
			if sy // x == ey // y:
				print('YES')
			else:
				print('NO')
		elif sx == 2 and ex == 1:
			if sy // y == ey // x:
				print('YES')
			else:
				print('NO')
		elif sx == 2 and ex == 2:
			if sy // y == ceil(ey // y):
				print('YES')
			else:
				print('NO')
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

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

def input():
	return sys.stdin.readline().strip()
main()


import math
(n, m, q) = list(map(int, input().split()))
a = math.gcd(n, m)
ns = n // a
ms = m // a
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	sy = (sy - 1) // (ns if sx == 1 else ms)
	ey = (ey - 1) // (ns if ex == 1 else ms)
	print('YES' if sy == ey else 'NO')


(n, m, q) = map(int, input().split())
import math
g = math.gcd(n, m)
for _ in range(q):
	(a, x, b, y) = map(int, input().split())
	il = n // g
	ol = m // g
	loc1 = (x - 1) // (il if a == 1 else ol)
	loc2 = (y - 1) // (il if b == 1 else ol)
	print('YES' if loc1 == loc2 else 'NO')


def gcd_recursive(a, b):
	if b == 0:
		return a
	else:
		return gcd_recursive(b, a % b)
(n, m, q) = input().split()
n = int(n)
m = int(m)
q = int(q)
base = gcd_recursive(n, m)
for ii in range(0, q):
	(sx, sy, ex, ey) = input().split()
	sx = int(sx)
	sy = int(sy) - 1
	ex = int(ex)
	ey = int(ey) - 1
	if sx == 1:
		sy = sy // (n // base)
	else:
		sy = sy // (m // base)
	if ex == 1:
		ey = ey // (n // base)
	else:
		ey = ey // (m // base)
	if sy == ey:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m, k) = map(int, input().split(' '))
gcd = math.gcd(n, m)
xd = [0] * 3
xd[1] = n // gcd
xd[2] = m // gcd
for i in range(k):
	(a, x, b, y) = map(int, input().split(' '))
	if gcd == 1:
		print('YES')
	elif (x - 1) // xd[a] == (y - 1) // xd[b]:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())
import math
y = math.gcd(n, m)
one = n // y
two = m // y
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	b = b - 1
	d = d - 1
	if a == c == 1:
		if b // one == d // one:
			print('YES')
		else:
			print('NO')
	if a == 2 and c == 2:
		if b // two == d // two:
			print('YES')
		else:
			print('NO')
	if a == 1 and c == 2:
		if b // one == d // two:
			print('YES')
		else:
			print('NO')
	if a == 2 and c == 1:
		if b // two == d // one:
			print('YES')
		else:
			print('NO')


def gcd(x, y):
	while x > 0 and y > 0:
		x %= y
		(x, y) = (y, x)
	return y + x

def lcm(x, y):
	return x * y // gcd(x, y)
(n, m, q) = [int(x) for x in input().strip().split()]
L = lcm(n, m)
a = L // m
b = L // n
k = lcm(a, b)
v = [0, b, a]
for i in range(q):
	(x1, x2, y1, y2) = [int(x) for x in input().strip().split()]
	t1 = x2 * v[x1] // k
	r1 = x2 * v[x1] % k
	t2 = y2 * v[y1] // k
	r2 = y2 * v[y1] % k
	if r1 == 0:
		t1 -= 1
	if r2 == 0:
		t2 -= 1
	if t1 == t2:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())
query = [list(map(int, input().split())) for i in range(q)]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
gcd_nm = gcd(n, m)
part_n = n // gcd_nm
part_m = m // gcd_nm
for i in range(q):
	(sx, sy, ex, ey) = query[i]
	if sx == 1 and ex == 1:
		if (sy - 1) // part_n == (ey - 1) // part_n:
			print('YES')
		else:
			print('NO')
	if sx == 2 and ex == 2:
		if (sy - 1) // part_m == (ey - 1) // part_m:
			print('YES')
		else:
			print('NO')
	if sx == 1 and ex == 2:
		if (sy - 1) // part_n == (ey - 1) // part_m:
			print('YES')
		else:
			print('NO')
	if sx == 2 and ex == 1:
		if (sy - 1) // part_m == (ey - 1) // part_n:
			print('YES')
		else:
			print('NO')


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

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)
(n, m, q) = mi()
g = math.gcd(n, m)
a = n // g
b = m // g
for i in range(q):
	(sx, sy, ex, ey) = mi()
	s = cdiv(sy, a) if sx == 1 else cdiv(sy, b)
	e = cdiv(ey, a) if ex == 1 else cdiv(ey, b)
	print('YES') if s == e else print('NO')


import math

def haha(l, r):
	return (l - 1) // r

def forever(l, r):
	return l + r
(n, k, q) = map(int, input().split(' '))
num = n * k // math.gcd(n, k)
for i in range(0, q):
	(x1, y1, x2, y2) = map(int, input().split(' '))
	if x1 == 1:
		sum1 = y1 * k
	else:
		sum1 = y1 * n
	if x2 == 1:
		sum2 = y2 * k
	else:
		sum2 = y2 * n
	if haha(sum1, num) == haha(sum2, num):
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
d = math.gcd(n, m)
(nd, md) = (n // d, m // d)
for _ in range(q):
	(x, y, u, v) = map(int, input().split())
	y -= 1
	v -= 1
	if x == 1:
		y //= nd
	else:
		y //= md
	if u == 1:
		v //= nd
	else:
		v //= md
	if y == v:
		print('YES')
	else:
		print('NO')


import math as ma
from sys import exit

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def checks(a, b, x):
	if (a - 1) // x == (b - 1) // x:
		return 'YES'
	return 'NO'

def checkd(a, b, c, d):
	if (a - 1) // b == (c - 1) // d:
		return 'YES'
	return 'NO'

def solve():
	t = 1
	for tt in range(t):
		(n, m, q) = num()
		gg = find_gcd(n, m)
		ox = n // gg
		xp = m // gg
		for i in range(q):
			(a, b, c, d) = num()
			if a == c:
				if a == 1:
					print(checks(b, d, ox))
				else:
					print(checks(b, d, xp))
			else:
				yp = [(a, b), (c, d)]
				yp.sort()
				print(checkd(yp[0][1], ox, yp[1][1], xp))
solve()


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m, q) = map(int, input().split())
g = gcd(n, m)
l = n * m // g
x = l // n
y = l // m
(x, y) = (y, x)
for i in range(q):
	(c1, n1, c2, n2) = map(int, input().split())
	n1 -= 1
	n2 -= 1
	if c1 == 1:
		t1 = n1 // x
	else:
		t1 = n1 // y
	if c2 == 1:
		t2 = n2 // x
	else:
		t2 = n2 // y
	if t1 == t2:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
(n, m, q) = map(int, input().split())
import math
GCD = math.gcd(n, m)
k = n // GCD
l = m // GCD

def div(x, y):
	if x == 1:
		return (y - 1) // k
	else:
		return (y - 1) // l
for testcases in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if div(sx, sy) == div(ex, ey):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def gcd(x, y):
	if x < y:
		(x, y) = (y, x)
	if y == 0:
		return x
	return gcd(y, x % y)
(n, m, q) = map(int, input().split())
g = gcd(n, m)
n_wall = n // g
m_wall = m // g
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if a == 1:
		r1 = (b + n_wall - 1) // n_wall
	else:
		r1 = (b + m_wall - 1) // m_wall
	if c == 1:
		r2 = (d + n_wall - 1) // n_wall
	else:
		r2 = (d + m_wall - 1) // m_wall
	print('YES' if r1 == r2 else 'NO')


from decimal import *

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(n, m, q) = map(int, input().split())
g = gcd(n, m)
for _ in range(q):
	(sx, sy, gx, gy) = map(int, input().split())
	if sx == 1:
		s_group = Decimal(sy - 1) // Decimal(n / g)
	else:
		s_group = Decimal(sy - 1) // Decimal(m / g)
	if gx == 1:
		g_group = Decimal(gy - 1) // Decimal(n / g)
	else:
		g_group = Decimal(gy - 1) // Decimal(m / g)
	if s_group == g_group:
		print('YES')
	else:
		print('NO')


import sys, math
input = lambda : sys.stdin.readline().strip('\r\n')
(n, m, q) = map(int, input().split())
d = math.gcd(n, m)
nd = n // d
md = m // d
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		x = (sy - 1) // nd
	else:
		x = (sy - 1) // md
	if ex == 1:
		y = (ey - 1) // nd
	else:
		y = (ey - 1) // md
	print('YES' if x == y else 'NO')


from math import gcd
[n, m, q] = [int(v) for v in input().split()]

def f(a, b):
	b -= 1
	if a == 1:
		return m * b
	else:
		return n * b
com = n * m // gcd(n, m)
for _ in range(q):
	[sx, sy, ex, ey] = [int(v) for v in input().split()]
	a = f(sx, sy)
	b = f(ex, ey)
	[a, b] = sorted([a, b])
	k = com * (a // com + 1)
	print('YES' if b < k else 'NO')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

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

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(n, m, q) = mi()
	g = gcd(n, m)
	n //= g
	m //= g
	for i in range(q):
		(x, y, a, b) = mi()
		if x == 1:
			y = (y - 1) // n
		else:
			y = (y - 1) // m
		if a == 1:
			b = (b - 1) // n
		else:
			b = (b - 1) // m
		if y == b:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
(f, s) = (n // g, m // g)
for nt in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx != ex:
		if sx == 1:
			print('YES' if (sy - 1) // f == (ey - 1) // s else 'NO')
		else:
			print('YES' if (sy - 1) // s == (ey - 1) // f else 'NO')
	elif sx == 1:
		print('YES' if (sy - 1) // f == (ey - 1) // f else 'NO')
	else:
		print('YES' if (sy - 1) // s == (ey - 1) // s else 'NO')


from math import gcd
(n, m, q) = map(int, input().strip().split())
g = gcd(n, m)
(f0, f1) = (n // g, m // g)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().strip().split())
	if sx == 1:
		b00 = (sy - 1) // f0
	else:
		b00 = (sy - 1) // f1
	if ex == 1:
		b10 = (ey - 1) // f0
	else:
		b10 = (ey - 1) // f1
	if b00 == b10:
		print('YES')
	else:
		print('NO')


q = list(map(int, input().split()))
import math
e = math.gcd(q[0], q[1])
n = q[0] // e
m = q[1] // e
for i in range(q[2]):
	w = list(map(int, input().split()))
	if w[0] == 1 and w[2] == 2:
		if (w[1] - 1) // n == (w[3] - 1) // m:
			print('YES')
		else:
			print('NO')
	elif w[0] == 2 and w[2] == 1:
		if (w[1] - 1) // m == (w[3] - 1) // n:
			print('YES')
		else:
			print('NO')
	elif w[0] == 1 and w[2] == 1:
		if (w[1] - 1) // n == (w[3] - 1) // n:
			print('YES')
		else:
			print('NO')
	elif w[0] == 2 and w[2] == 2:
		if (w[1] - 1) // m == (w[3] - 1) // m:
			print('YES')
		else:
			print('NO')


(n, m, q) = map(int, input().split())
div = 0
ansar = []
n2 = n
m2 = m
while n2 * m2 > 0:
	if n2 >= m2:
		n2 = n2 % m2
	else:
		m2 = m2 % n2
div = m2 + n2
for i in range(q):
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 == x2 == 1:
		if (y1 - 1) * div // n == (y2 - 1) * div // n:
			ansar.append('YES')
		else:
			ansar.append('NO')
	elif x1 == x2 == 2:
		if (y1 - 1) * div // m == (y2 - 1) * div // m:
			ansar.append('YES')
		else:
			ansar.append('NO')
	elif x1 == 1 and x2 == 2:
		if (y1 - 1) * div // n == (y2 - 1) * div // m:
			ansar.append('YES')
		else:
			ansar.append('NO')
	elif (y1 - 1) * div // m == (y2 - 1) * div // n:
		ansar.append('YES')
	else:
		ansar.append('NO')
print(*ansar, sep='\n')


import math

def lcd(a, b):
	return int(int(a) * int(b) / math.gcd(int(a), int(b)))
(n, m, q) = [int(i) for i in input().split()]
a = lcd(n, m)
inp = int(a // n)
out = int(a // m)
stp = lcd(inp, out)
for i in range(0, q):
	(sx, sy, ex, ey) = [int(i) for i in input().split()]
	if sx == 1:
		sy = int(sy * inp)
	else:
		sy = int(sy * out)
	if ex == 1:
		ey = int(ey * inp)
	else:
		ey = int(ey * out)
	if int(int(sy + stp - 1) // stp) == int(int(ey + stp - 1) // stp):
		print('YES\n')
	else:
		print('NO\n')


import math

def lcm(a, b):
	return a * b // math.gcd(a, b)
(n, m, q) = map(int, input().split())
l = lcm(n, m)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		s_area = m * sy // l
	elif sx == 2:
		s_area = n * sy // l
	if ex == 1:
		e_area = m * ey // l
	elif ex == 2:
		e_area = n * ey // l
	if s_area == e_area:
		print('YES')
	else:
		print('NO')


def compute_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def compute_lcm(x, y):
	lcm = x * y // compute_gcd(x, y)
	return lcm
(n, m, q) = map(int, input().split())
val = compute_lcm(n, m)
first = val // m
second = val // n
for j in range(q):
	(a, b, c, d) = map(int, input().split())
	if a == c:
		x = first if a == 1 else second
		if (b - 1) // x == (d - 1) // x:
			print('YES')
		else:
			print('NO')
	else:
		x = first if a == 1 else second
		y = first if c == 1 else second
		if (b - 1) // x == (d - 1) // y:
			print('YES')
		else:
			print('NO')


import sys
l = [int(i) for i in input().split(' ')]
n = l[0]
m = l[1]
q = l[2]
na = [n, m]
num = -1
while True:
	na = sorted(na)
	if na[0] == na[1]:
		num = na[0]
		break
	if na[1] > na[0] * 2:
		na[1] = na[1] % na[0] + na[0] * 2
	nna = na.copy()
	nna[0] = na[0]
	nna[1] = na[1] - na[0]
	na = nna
for i in range(0, q):
	c = [int(j) for j in sys.stdin.readline().rstrip().split(' ')]
	cn = [0, 0]
	if c[0] == 1:
		cn[0] = (c[1] - 1) // (n // num)
	else:
		cn[0] = (c[1] - 1) // (m // num)
	if c[2] == 1:
		cn[1] = (c[3] - 1) // (n // num)
	else:
		cn[1] = (c[3] - 1) // (m // num)
	if cn[0] == cn[1]:
		print('YES')
	else:
		print('NO')


(n, m, q) = map(int, input().split())
from math import gcd
g = gcd(n, m)
out = []
n //= g
m //= g
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	sp = sy // (n if sx == 1 else m)
	ep = ey // (n if ex == 1 else m)
	out.append('YES' if sp == ep else 'NO')
print(*out, sep='\n')


import sys
input = sys.stdin.readline
(n, m, q) = map(int, input().split())

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
d = gcd(n, m)
l = n * m // d

def f(a1, a2, b1, b2):
	if a1 == 1:
		a = (a2 * m - 1) // l
	else:
		a = (a2 * n - 1) // l
	if b1 == 1:
		b = (b2 * m - 1) // l
	else:
		b = (b2 * n - 1) // l
	return a == b
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if f(sx, sy, ex, ey):
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = [int(i) for i in input().split()]
g = math.gcd(n, m)
ng = n // g
mg = m // g
for i in range(q):
	data = [int(i) for i in input().split()]
	group = [0, 0]
	for j in range(2):
		if data[2 * j] == 1:
			group[j] = (data[2 * j + 1] - 1) // ng
		else:
			group[j] = (data[2 * j + 1] - 1) // mg
	if group[0] == group[1]:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = [int(s) for s in input().split()]
g = gcd(n, m)
(n, m) = map(lambda x: x // g, [n, m])
for _ in range(q):
	(sx, sy, ex, ey) = map(lambda x: x - 1, [int(s) for s in input().split()])
	if sy // [n, m][sx] == ey // [n, m][ex]:
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
walls = gcd(n, m)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	(fst, scd) = (0, 0)
	if sx == 1:
		fst = (sy - 1) * walls // n
	else:
		fst = (sy - 1) * walls // m
	if ex == 1:
		scd = (ey - 1) * walls // n
	else:
		scd = (ey - 1) * walls // m
	if fst == scd:
		print('YES')
	else:
		print('NO')


from fractions import gcd
(N, M, Q) = map(int, input().split())
data = []
for _ in range(Q):
	A = list(map(int, input().split()))
	data.append(A)
C = gcd(N, M)
(rn, rm) = (N // C, M // C)

def zone(px, py):
	if px == 1:
		return (py - 1) // rn
	else:
		return (py - 1) // rm
for (sx, sy, ex, ey) in data:
	zs = zone(sx, sy)
	ze = zone(ex, ey)
	if zs == ze:
		print('YES')
	else:
		print('NO')


from math import gcd

def main():
	(n, m, q) = map(int, input().split())
	l = n * m // gcd(n, m)
	n = l // n
	m = l // m
	k = n * m // gcd(n, m)
	for i in range(q):
		(sx, sy, ex, ey) = map(int, input().split())
		if sx == 1:
			sy = (sy - 1) * n
		else:
			sy = (sy - 1) * m
		if ex == 1:
			ey = (ey - 1) * n
		else:
			ey = (ey - 1) * m
		if sy // k == ey // k:
			print('YES')
		else:
			print('NO')
main()


import math
(n, m, q) = list(map(int, input().split()))
hcf = math.gcd(n, m)
d = [0, n // hcf, m // hcf]
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	ps = (sy - 1) // d[sx]
	pe = (ey - 1) // d[ex]
	if ps == pe:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(n, m, q) = tuple(map(int, input().split()))
g = gcd(n, m)
x1 = n // g
x2 = m // g
for w in range(q):
	(a1, b1, a2, b2) = tuple(map(int, input().split()))
	if a1 == a2:
		if a1 == 1:
			if (b1 - 1) // x1 == (b2 - 1) // x1:
				print('YES')
			else:
				print('NO')
		elif (b1 - 1) // x2 == (b2 - 1) // x2:
			print('YES')
		else:
			print('NO')
	elif a1 == 1:
		if (b1 - 1) // x1 == (b2 - 1) // x2:
			print('YES')
		else:
			print('NO')
	elif (b1 - 1) // x2 == (b2 - 1) // x1:
		print('YES')
	else:
		print('NO')


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

def lcm(a, b):
	return a // gcd(a, b) * b
(n, m, q) = map(int, input().split())
g = lcm(n, m)
cm = g // n
cn = g // m
while q > 0:
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		sy = sy // cn
	else:
		sy = sy // cm
	if ex == 1:
		ey = ey // cn
	else:
		ey = ey // cm
	if sy == ey:
		print('YES')
	else:
		print('NO')
	q -= 1


def gcd(x, y):
	z = x % y
	while z != 0:
		x = y
		y = z
		z = x % y
	return y
(n, m, q) = map(int, input().split())
g = gcd(n, m)

def f(x, y):
	if x == 1:
		return y * g // n
	else:
		return y * g // m
for o in range(0, q):
	(sx, sy, ex, ey) = map(int, input().split())
	if f(sx, sy - 1) == f(ex, ey - 1):
		print('YES')
	else:
		print('NO')


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

def lcm(a, b):
	return a * b // gcd(a, b)
l1 = [int(x) for x in input().split()]
n = l1[0]
m = l1[1]
q = l1[2]
lcmval = lcm(n, m)
for i in range(q):
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	sy -= 1
	ey -= 1
	sy *= m if sx == 1 else n
	ey *= m if ex == 1 else n
	if sy // lcmval == ey // lcmval:
		print('YES')
	else:
		print('NO')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m, q) = map(int, input().split())
x = gcd(max(n, m), min(n, m))
n1 = n // x
m1 = m // x
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	b -= 1
	d -= 1
	if a == 1:
		p1 = b // n1
	else:
		p1 = b // m1
	if c == 1:
		p2 = d // n1
	else:
		p2 = d // m1
	if p1 == p2:
		print('YES')
	else:
		print('NO')


import math

def lcm(a, b):
	return a // math.gcd(a, b) * b
(n, m, q) = input().split()
n = int(n)
m = int(m)
q = int(q)
total_length = lcm(n, m)
inner_length = total_length // n
outer_length = total_length // m
circle = lcm(inner_length, outer_length)
for i in range(q):
	(ff, fs, sf, ss) = input().split()
	ff = int(ff)
	fs = int(fs)
	ss = int(ss)
	sf = int(sf)
	pos_of_first = 0
	pos_of_second = 0
	if ff == 1:
		pos_of_first = fs * inner_length
	else:
		pos_of_first = fs * outer_length
	if sf == 1:
		pos_of_second = ss * inner_length
	else:
		pos_of_second = ss * outer_length
	if pos_of_first // circle + (pos_of_first % circle != 0) == pos_of_second // circle + (pos_of_second % circle != 0):
		print('YES')
	else:
		print('NO')


from math import gcd
(n, m, q) = map(int, input().split())
l1 = [0] * 3
l1[1] = n // gcd(n, m)
l1[2] = m // gcd(n, m)
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if (sy - 1) // l1[sx] == (ey - 1) // l1[ex]:
		print('YES')
	else:
		print('NO')


def ceil(a, b):
	if a % b == 0:
		return a // b
	return a // b + 1

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(n, m, q) = [int(i) for i in input().split()]
gc = gcd(n, m)
inner = n // gc
outer = m // gc
for i in range(q):
	(sx, sy, ex, ey) = [int(i) for i in input().split()]
	if sx == 1:
		sec = ceil(sy, inner)
	else:
		sec = ceil(sy, outer)
	if ex == 1:
		fir = ceil(ey, inner)
	else:
		fir = ceil(ey, outer)
	if fir == sec:
		print('YES')
	else:
		print('NO')


import math
(n, m, l) = map(int, input().split(' '))
k = math.gcd(n, m)
a = [int(n // k), int(m // k)]
for i in range(l):
	(x, y, x_1, y_1) = map(int, input().split(' '))
	if int((y - 1) // a[x - 1]) == int((y_1 - 1) // a[x_1 - 1]):
		print('YES')
	else:
		print('NO')


from math import gcd
from decimal import Decimal
(n, m, q) = map(int, input().split())
g = Decimal(gcd(n, m))
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	pos1 = 0
	pos2 = 0
	if sx == 1:
		pos1 = Decimal(g * sy / n)
	else:
		pos1 = Decimal(g * sy / m)
	if ex == 1:
		pos2 = Decimal(g * ey / n)
	else:
		pos2 = Decimal(g * ey / m)
	if not pos1 % 1:
		pos1 -= 1
	if not pos2 % 1:
		pos2 -= 1
	if pos1 // 1 == pos2 // 1:
		print('YES')
	else:
		print('NO')


def gcd(x, y):
	if y != 0:
		return gcd(y, x % y)
	return x
s = input().split(' ')
n = int(s[0])
m = int(s[1])
q = int(s[2])
GCD = gcd(n, m)
block = n * m // GCD
while q != 0:
	s = input().split(' ')
	sx = int(s[0])
	sy = int(s[1])
	ex = int(s[2])
	ey = int(s[3])
	if sx == 1:
		sy = m * (sy - 1)
	else:
		sy = n * (sy - 1)
	if ex == 1:
		ey = m * (ey - 1)
	else:
		ey = n * (ey - 1)
	if ey // block == sy // block:
		print('YES')
	else:
		print('NO')
	q -= 1


import math
(n, m, q) = map(int, input().split())
gcd = math.gcd(n, m)
gn = n // gcd
gm = m // gcd

def get_pos(p):
	if p[0] == 1:
		return (p[1] - 1) // gn
	return (p[1] - 1) // gm

def possible(start, end):
	start_pos = get_pos(start)
	end_pos = get_pos(end)
	return start_pos == end_pos
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	r = possible((sx, sy), (ex, ey))
	print('YES' if r else 'NO')


(n, m, q) = map(int, input().strip().split())
import fractions
p = fractions.gcd(n, m)
c = n // p
d = m // p
for cases in range(q):
	(sx, sy, ex, ey) = map(int, input().strip().split())
	if sx == 1 and ex == 2:
		w = (sy - 1) // c
		z = (ey - 1) // d
		if w == z:
			print('YES')
		else:
			print('NO')
	elif ex == 1 and sx == 2:
		w = (sy - 1) // d
		z = (ey - 1) // c
		if w == z:
			print('YES')
		else:
			print('NO')
	elif sx == 1 and ex == 1:
		w = (sy - 1) // c
		z = (ey - 1) // c
		if w == z:
			print('YES')
		else:
			print('NO')
	else:
		w = (sy - 1) // d
		z = (ey - 1) // d
		if w == z:
			print('YES')
		else:
			print('NO')


import sys
from math import gcd
(N, M, Q) = list(map(int, sys.stdin.readline().split()))
for q in range(Q):
	(a, b, c, d) = list(map(int, sys.stdin.readline().split()))
	wall = gcd(N, M)
	divisor1 = N // wall
	divisor2 = M // wall
	if a == 1:
		k1 = (b - 1) // divisor1
	elif a == 2:
		k1 = (b - 1) // divisor2
	if c == 1:
		k2 = (d - 1) // divisor1
	elif c == 2:
		k2 = (d - 1) // divisor2
	if k1 == k2:
		print('YES')
	if k1 != k2:
		print('NO')


import sys
input = sys.stdin.readline
(n, m, q) = list(map(int, input().split()))

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
gcd = computeGCD(n, m)
factorN = n // gcd
factorM = m // gcd
for _ in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	if sx != ex:
		if sx == 1:
			factor = factorN
			opsFactor = factorM
		else:
			factor = factorM
			opsFactor = factorN
		rem = (sy - 1) // factor
		sy = rem * opsFactor + 1
		sx = ex
	if ex == 1:
		factor = factorN
	else:
		factor = factorM
	rem = (sy - 1) // factor
	sy = rem * factor + 1
	if ey - sy < 0 or ey - sy >= factor:
		print('NO')
	else:
		print('YES')


def gcd(a, b):
	while b != 0:
		temp = b
		b = a % b
		a = temp
	return a

def lcm(a, b):
	return a // gcd(a, b) * b
(n, m, q) = map(int, input().split())
b = lcm(n, m)
for ti in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	if sx == 1:
		px = sy * m // b
	else:
		px = sy * n // b
	if ex == 1:
		py = ey * m // b
	else:
		py = ey * n // b
	if px == py:
		print('YES')
	else:
		print('NO')


(unitn, unitm) = (0, 0)
(n, m, ln, lm) = (0, 0, 0, 0)
q = 0
s = [0, 0]
t = [0, 0]

def gcd(a, b):
	while b > 0:
		c = a % b
		a = b
		b = c
	return int(a)

def lcm(a, b):
	return int(a * b // gcd(a, b))

def trans(p):
	global unitn, unitm
	if p[0] == 1:
		return int((p[1] - 1) // unitn)
	else:
		return int((p[1] - 1) // unitm)
(n, m, q) = map(int, input().split())
tot = lcm(n, m)
ln = tot // n
lm = tot // m
leng = lcm(ln, lm)
num = tot // leng
unitn = n // num
unitm = m // num
for kk in range(q):
	(s[0], s[1], t[0], t[1]) = map(int, input().split())
	ida = trans(s)
	idb = trans(t)
	if ida == idb:
		print('YES')
	else:
		print('NO')


from math import gcd, ceil
(n, m, q) = map(int, input().split())
g = gcd(n, m)

def findpart(a, b):
	if a == 1:
		return (b - 1) // (n // g)
	else:
		return (b - 1) // (m // g)
for i in range(q):
	(s1, s2, e1, e2) = map(int, input().split())
	if findpart(s1, s2) == findpart(e1, e2):
		print('YES')
	else:
		print('NO')


(n, m, q) = [int(x) for x in input().split()]
import math
hcf = math.gcd(n, m)
n = n // hcf
m = m // hcf
while q:
	q = q - 1
	(sx, sy, ex, ey) = [int(x) for x in input().split()]
	sy -= 1
	ey -= 1
	sy //= m if sx - 1 else n
	ey //= m if ex - 1 else n
	if sy == ey:
		print('YES')
	else:
		print('NO')


import math
import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, q) = list(map(int, input().split()))
hcf = math.gcd(n, m)
d = [0, n // hcf, m // hcf]
for i in range(q):
	(sx, sy, ex, ey) = list(map(int, input().split()))
	ps = (sy - 1) // d[sx]
	pe = (ey - 1) // d[ex]
	if ps == pe:
		print('YES')
	else:
		print('NO')


from math import ceil
(n, m, q) = map(int, input().split())

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

def lcm(a, b):
	return a * b // gcd(a, b)
t = gcd(n, m)
for i in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if t == 1:
		print('YES')
	elif m == n:
		if sy == ey:
			print('YES')
		else:
			print('NO')
	else:
		if sx == 1:
			a = (sy - 1) // (n // t)
		elif sx == 2:
			a = (sy - 1) // (m // t)
		if ex == 1:
			b = (ey - 1) // (n // t)
		elif ex == 2:
			b = (ey - 1) // (m // t)
		if a == b:
			print('YES')
		else:
			print('NO')


import math
(n, m, q) = map(int, input().split())
g = math.gcd(n, m)
nm1 = [1, 1, 1]
nm1[1] = n // g
nm1[2] = m // g

def bsn(x, y):
	return (y - 1) // nm1[x]
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	print('YES' if bsn(sx, sy) == bsn(ex, ey) else 'NO')


import sys
import math
(n, m, q) = map(int, sys.stdin.readline().split())
gcd = math.gcd(n, m)

def find_segment(sx, sy):
	if sx == 1:
		return (sy - 1) * gcd // n
	else:
		return (sy - 1) * gcd // m
for query in range(q):
	(sx, sy, ex, ey) = map(int, sys.stdin.readline().split())
	s1 = find_segment(sx, sy)
	s2 = find_segment(ex, ey)
	print('YES' if s1 == s2 else 'NO')


from math import *
MOD = int(1000000000.0) + 7

def nextInt():
	return int(input())

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

def YN(x):
	return 'YES' if x else 'NO'
(n, m, g, q) = (0, 0, 0, 0)

def comp(x, y):
	global n, m, g
	y -= 1
	if x == 1:
		return y // (n // g)
	else:
		return y // (m // g)

def solve():
	global n, m, g, q
	(n, m, q) = nextInts()
	g = gcd(n, m)
	for i in range(q):
		(sx, sy, ex, ey) = nextInts()
		if comp(sx, sy) == comp(ex, ey):
			print('YES')
		else:
			print('NO')
solve()


import os
import sys
from io import BytesIO, IOBase
from math import gcd

def solution():
	pass

def main():
	(n, m, q) = r_array()
	hcf = gcd(n, m)
	(it1, it2) = (n // hcf, m // hcf)

	def ceil(x, y):
		return x // y if x % y == 0 else x // y + 1
	for _ in range(q):
		(sx, sy, ex, ey) = r_array()
		group1 = ceil(sy, it1) if sx == 1 else ceil(sy, it2)
		group2 = ceil(ey, it1) if ex == 1 else ceil(ey, it2)
		write('YES' if group1 == group2 else 'NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
n //= g
m //= g
a = [n, m]
for _ in range(q):
	(sx, sy, ex, ey) = map(lambda x: int(x) - 1, input().split())
	if sy // a[sx] == ey // a[ex]:
		print('yes')
	else:
		print('no')


from math import gcd
(n, m, q) = map(int, input().split())
g = gcd(n, m)
lc = n // g * m
for __ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sy -= 1
	ey -= 1
	sy *= m if sx == 1 else n
	ey *= m if ex == 1 else n
	print('YES' if sy // lc == ey // lc else 'NO')


(a, b, c) = map(int, input().split())
nod = 0
(a1, b1) = (a, b)
while a != 0 and b != 0:
	(a, b) = (b, a % b)
nod = max(a, b)
for i in range(c):
	(c, d, e, f) = map(int, input().split())
	d -= 1
	f -= 1
	if c == 1:
		k = d // (a1 // nod)
	else:
		k = d // (b1 // nod)
	if e == 1:
		n = f // (a1 // nod)
	else:
		n = f // (b1 // nod)
	if n == k:
		print('YES')
	else:
		print('NO')


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

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(n, m, q) = mp()
st = gcd(n, m)
stn = n // st
stm = m // st
for qq in range(q):
	(s, x, e, y) = mp()
	if s == 1:
		x = (x + stn - 1) // stn
	else:
		x = (x + stm - 1) // stm
	if e == 1:
		y = (y + stn - 1) // stn
	else:
		y = (y + stm - 1) // stm
	if x == y:
		print('YES')
	else:
		print('NO')


import math
(n, m, q) = map(int, input().split())
temp = math.gcd(n, m)
sm = m // temp
sn = n // temp
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	if sx == 1:
		t1 = (sy - 1) // sn
	else:
		t1 = (sy - 1) // sm
	if ex == 1:
		t2 = (ey - 1) // sn
	else:
		t2 = (ey - 1) // sm
	print('YES' if t1 == t2 else 'NO')


import sys
import math
(n, m, q) = [int(_) for _ in sys.stdin.readline().strip().split()]
d = math.gcd(n, m)
(nd, md) = (n // d, m // d)
for _ in range(q):
	(sx, sy, ex, ey) = [int(_) for _ in sys.stdin.readline().strip().split()]
	if sx == 1:
		sy = (sy - 1) // nd
	else:
		sy = (sy - 1) // md
	if ex == 1:
		ey = (ey - 1) // nd
	else:
		ey = (ey - 1) // md
	if sy == ey:
		sys.stdout.write('YES\n')
	else:
		sys.stdout.write('NO\n')


from math import gcd
(n, m, q) = map(int, input().split())
d = gcd(m, n)
for j in range(q):
	(s1, s2, e1, e2) = map(int, input().split())
	s2 -= 1
	e2 -= 1
	if s1 == 1:
		t1 = (s2 - s2 % (n // d)) // (n // d)
	else:
		t1 = (s2 - s2 % (m // d)) // (m // d)
	if e1 == 1:
		t2 = (e2 - e2 % (n // d)) // (n // d)
	else:
		t2 = (e2 - e2 % (m // d)) // (m // d)
	if t1 == t2:
		print('YES')
	else:
		print('NO')


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from random import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = 1
while t:
	t -= 1
	(n, m, q) = ma()
	g = gcd(n, m)
	x = n // g
	y = m // g
	for i in range(q):
		(a, b, c, d) = ma()
		if a == 1:
			z = b // x
			if b % x == 0:
				z -= 1
		else:
			z = b // y
			if b % y == 0:
				z -= 1
		if c == 1:
			z1 = d // x
			if d % x == 0:
				z1 -= 1
		else:
			z1 = d // y
			if d % y == 0:
				z1 -= 1
		if z == z1:
			print('YES')
		else:
			print('NO')


import sys
import math
inp = sys.stdin

def process_test(len_inner, len_outer):
	(sx, sy, ex, ey) = map(int, inp.readline().split())
	solve(sx, sy, ex, ey, len_inner, len_outer)

def accumu(end, diff):
	total = 0
	for x in range(end):
		total += diff
		yield total

def solve(sx, sy, ex, ey, len_inner, len_outer):
	gcd = math.gcd(len_inner, len_outer)
	first_pos = (sy - 1) // (len_inner // gcd if sx == 1 else len_outer // gcd)
	second_pos = (ey - 1) // (len_inner // gcd if ex == 1 else len_outer // gcd)
	if first_pos == second_pos:
		print('YES')
	else:
		print('NO')
(len_inner, len_outer, num_tests) = map(int, inp.readline().split())
for t in range(num_tests):
	process_test(len_inner, len_outer)


import sys

def input():
	return sys.stdin.readline()[:-1]
(n, m, q) = list(map(int, input().split()))

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
g = gcd(n, m)
for i in range(q):
	(s1, s2, e1, e2) = list(map(int, input().split()))
	if s1 == 1:
		scheck = n // g
	else:
		scheck = m // g
	if e1 == 1:
		echeck = n // g
	else:
		echeck = m // g
	if (s2 - 1) // scheck == (e2 - 1) // echeck:
		print('YES')
	else:
		print('NO')


n = [0, 0]
(n[0], n[1], q) = map(int, input().split())
from math import gcd
g = gcd(n[0], n[1])
for _ in range(q):
	(sx, sy, ex, ey) = map(int, input().split())
	sx -= 1
	sy -= 1
	ex -= 1
	ey -= 1
	if sy * g // n[sx] == ey * g // n[ex]:
		print('YES')
	else:
		print('NO')


import math
(N, K, q) = map(int, input().split(' '))
cnt = N * K // math.gcd(N, K)
tmp = int(0)
tmp = 1 * 2
tmp = 3 * 4
for i in range(0, q):
	(A, B, C, D) = map(int, input().split(' '))
	Y = int(0)
	X = int(0)
	if A == 1:
		X = B * K
	else:
		X = B * N
	if C == 1:
		Y = D * K
	else:
		Y = D * N
	if (X - 1) // cnt == (Y - 1) // cnt:
		print('YES')
	else:
		print('NO')


import sys, math, bisect
from collections import defaultdict
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def factor(n):
	potentional_p = 3
	itog_list = {}
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			if n in itog_list:
				itog_list[n] += 1
			else:
				itog_list[n] = 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			if potentional_p in itog_list:
				itog_list[potentional_p] += 1
			else:
				itog_list[potentional_p] = 1
		potentional_p += 2
	return itog_list
(n, m, q) = list(map(int, input().split()))
gd = math.gcd(n, m)

def meth(num, idx):
	if idx == 1:
		if num % (n // gd) == 0:
			return (num - num % (n // gd)) // (n // gd) - 1
		return (num - num % (n // gd)) // (n // gd)
	else:
		if num % (m // gd) == 0:
			return (num - num % (m // gd)) // (m // gd) - 1
		return (num - num % (m // gd)) // (m // gd)
for _ in range(q):
	a = list(map(int, input().split()))
	fl = 0
	if a[0] == a[2] == 1 and meth(a[1], 1) == meth(a[3], 1):
		fl = 1
	elif a[0] == a[2] == 2 and meth(a[1], 2) == meth(a[3], 2):
		fl = 1
	elif a[0] == 1 and a[2] == 2 and (meth(a[1], 1) == meth(a[3], 2)):
		fl = 1
	elif a[0] == 2 and a[2] == 1 and (meth(a[1], 2) == meth(a[3], 1)):
		fl = 1
	if fl == 1:
		print('YES')
	else:
		print('NO')


import math
A = list(map(int, input().split()))
n = A[0]
m = A[1]
g = math.gcd(A[0], A[1])
c = n * m // g
ln = c // n
lm = c // m
g = math.gcd(ln, lm)
c = ln * lm // g
C = []
for i in range(3):
	C.append(0)
C[1] = ln
C[2] = lm
for i in range(A[2]):
	B = list(map(int, input().split()))
	l1 = C[B[0]] * B[1]
	l2 = C[B[2]] * B[3]
	sec1 = l1 // c
	if l1 % c == 0:
		sec1 -= 1
	sec2 = l2 // c
	if l2 % c == 0:
		sec2 -= 1
	if sec1 == sec2:
		print('YES')
	else:
		print('NO')


import math

def get_lcm(n1, n2):
	gcd = math.gcd(n1, n2)
	result = n1 * n2 // gcd
	return result
arr = [0] * 2
(arr[0], arr[1], q) = map(int, input().split())
lcm = get_lcm(arr[0], arr[1])
(d1, d2) = (lcm // arr[0], lcm // arr[1])
d3 = get_lcm(d1, d2)
d = lcm // d3
for _ in range(q):
	(a1, a2, b1, b2) = map(int, input().split())
	x = (a2 - 1) * d // arr[(a1 + 1) % 2]
	y = (b2 - 1) * d // arr[(b1 + 1) % 2]
	print('YES') if x == y else print('NO')


def compute_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, m, q) = map(int, input().split())
aa = compute_gcd(n, m)
aa = n * m // aa
ang1 = aa // m
ang2 = aa // n
for i in range(q):
	l1 = []
	l2 = []
	(x1, x2, y1, y2) = map(int, input().split())
	if x1 != y1:
		if x1 == 1:
			z = x2 // ang1
			x = y2 // ang2
			if x2 % ang1 == 0:
				z = x2 // ang1 - 1
			if y2 % ang2 == 0:
				x = y2 // ang2 - 1
		else:
			z = x2 // ang2
			x = y2 // ang1
			if x2 % ang2 == 0:
				z = x2 // ang2 - 1
			if y2 % ang1 == 0:
				x = y2 // ang1 - 1
		if z == x:
			print('YES')
		else:
			print('NO')
	else:
		if x1 == 1:
			z = x2 // ang1
			x = y2 // ang1
			if x2 % ang1 == 0:
				z = x2 // ang1 - 1
			if y2 % ang1 == 0:
				x = y2 // ang1 - 1
		else:
			z = x2 // ang2
			x = y2 // ang2
			if x2 % ang2 == 0:
				z = x2 // ang2 - 1
			if y2 % ang2 == 0:
				x = y2 // ang2 - 1
		if z == x:
			print('YES')
		else:
			print('NO')


def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, m, q) = [int(i) for i in input().split()]
gc = gcd(n, m)
kp = n * m // gc
bat1 = kp // n
bat2 = kp // m
gc2 = gcd(bat1, bat2)
kp2 = bat1 * bat2 // gc2
b1 = kp2 // bat1
b2 = kp2 // bat2
for i in range(q):
	(a, b, c, d) = [int(i) for i in input().split()]
	if a == 1 and c == 1:
		if (b - 1) // b1 == (d - 1) // b1:
			print('YES')
		else:
			print('NO')
	if a == 1 and c == 2:
		(a, c) = (c, a)
		(b, d) = (d, b)
	if a == 2 and c == 1:
		if (b - 1) // b2 == (d - 1) // b1:
			print('YES')
		else:
			print('NO')
	if a == 2 and c == 2:
		if (b - 1) // b2 == (d - 1) // b2:
			print('YES')
		else:
			print('NO')


(n, m, q) = map(int, input().split())

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
g = computeGCD(n, m)
nn = n // g
mm = m // g
y = nn * mm // computeGCD(nn, mm)
for i in range(q):
	(a1, x1, a2, x2) = map(int, input().split())
	x1 -= 1
	x2 -= 1
	if a1 == 1:
		x1 *= mm
	else:
		x1 *= nn
	if a2 == 1:
		x2 *= mm
	else:
		x2 *= nn
	if x1 // y != x2 // y:
		print('NO')
	else:
		print('YES')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
(n, m, q) = inpl()
g = math.gcd(n, m)
n //= g
m //= g
for _ in range(q):
	(a, b, c, d) = inpl()
	if a == 1:
		fro = (b + n - 1) // n
	else:
		fro = (b + m - 1) // m
	if c == 1:
		to = (d + n - 1) // n
	else:
		to = (d + m - 1) // m
	print('YES' if fro == to else 'NO')


import math

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

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

def ceil(a, b):
	if a % b == 0:
		return a // b
	return a // b + 1
z = input().split(' ')
i = 0
n = int(z[0])
m = int(z[1])
t = int(z[2])
l = lcm(n, m)
while i < t:
	x = input().split(' ')
	sx = int(x[0])
	sy = int(x[1])
	ex = int(x[2])
	ey = int(x[3])
	v1 = 0
	if sx == 1:
		v1 = m * sy
	else:
		v1 = n * sy
	v2 = 0
	if ex == 1:
		v2 = m * ey
	else:
		v2 = n * ey
	if ceil(v1, l) == ceil(v2, l):
		print('YES')
	else:
		print('NO')
	i = i + 1


from sys import stdin
from math import sqrt, gcd
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
(n, m, q) = R()
a = lcm(n, m)
x1 = a // n
y1 = a // m
g = lcm(x1, y1)
for jj in range(q):
	(a, b, c, d) = R()
	if a != 1:
		(a, b, c, d) = (c, d, a, b)
	(x, y) = (x1, y1)
	if a == 2:
		x = y
	elif c == 1:
		y = x
	print('YES' if hg(g, b * x) == hg(g, d * y) else 'NO')