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.

Difficulty: interview

Starter code:

Solutions:
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 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')

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()

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
    else:
        if 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))

import math

n, m, q = list(map(int, input().split()))
d = math.gcd(n, m)
nd, md = n // d, m // d

for _ in range(q):
    x, y, u, v = list(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')


from math import gcd


n, m, q = list(map(int, input().split()))
g = gcd(n, m)
sn, sm = n // g, m // g
for i in range(q):
	sx, sy, ex, ey = list(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
	if t1 == t2:
		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 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')


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")

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")


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")
        else:
            if sy//(n) == ey//(m):
                print("YES")
            else:
                print("NO")
    else:
        if ex == 1:
            if sy//(m) == ey//(n):
                print("YES")
            else:
                print("NO")
        else:
            if sy//(m) == ey//(m):
                print("YES")
            else:
                print("NO")


import math

n, m, q = list(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 = list(map(int, input().split()))
    print("YES" if bsn(sx, sy) == bsn(ex, ey) else "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 sys
input = sys.stdin.readline

n,m,q=list(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=list(map(int,input().split()))

    if div(sx,sy)==div(ex,ey):
        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) = 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")


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")

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')

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')

def gcd(a, b):
    if a%b == 0:
        return b
    else :
        return gcd(b, a % b)
        
n, m, q = list(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 = list(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')





import math
n, m, q = list(map(int, input().split()))
g = math.gcd(n, m)
for qq in range(q):
    a, b, c, d = list(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")



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=list(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=list(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")


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")


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 = list(map( int, input().split() ))
g = gcd(n, m)
n = n // g
m = m // g

for _ in range( q ):
    sx, sy, ex, ey = list(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" )