The followers of Psycho-Helmet religion follow a peculiar calendar – a normal year contains N days. Every K-th year is a “MOB” year. For example, if K = 4, then years 4, 8, 12, 16 \ldots are “MOB” years. A “MOB” year contains M additional days i.e. it contains N+M days. 
 
Given X, determine whether the day after (X-1) days from Day 1 of Year 1 falls in a “MOB” year.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line containing N, M, K and X — the number of days in a normal year, the number of days in a “MOB” year, the number of years between two “MOB” years and the integer X.

------ Output Format ------ 

For each test case, output YES on a new line if the day after (X-1) days from Year 1, Day 1 falls in a “MOB” year, and NO otherwise.

You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical).

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$1 ≤ N, M, K ≤ 10^{4}$
$1 ≤ X ≤ 10^{9}$

----- Sample Input 1 ------ 
3
2 1 4 17
3 7 5 50
3 7 5 61
----- Sample Output 1 ------ 
YES
NO
YES
----- explanation 1 ------ 
Test case 1: Since $N = 2$, $M = 1$ and $K = 4$, years $4, 8, 12, 16 \ldots$ are “MOB” years and:
- Year $1$ has $N = 2$ days.
- Year $2$ has $N = 2$ days.
- Year $3$ has $N = 2$ days.
- Year $4$ is a “MOB” year and has $N + M = 3$ days.
- Year $5$ has $N = 2$ days.
- Year $6$ has $N = 2$ days.
- Year $7$ has $N = 2$ days.
- Year $8$ is a “MOB” year and has $N + M = 3$ days.

The $X = 17$-th day falls on the second day of Year $8$, which is a “MOB” year. Hence the answer is YES.

Test case 2: The $X = 50$-th day falls on the third day of Year $12$, which is not a “MOB” year. Hence the answer is NO.

Test case 3: The $X = 61$-st day falls on the fifth day of Year $15$, which is a “MOB” year. Hence the answer is YES.

Source: codechef | Difficulty: EASY
Tags: Mathematics


Solutions:
for i in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	if x % (n * (k - 1) + n + m) > n * (k - 1) or x % (n * (k - 1) + n + m) == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	(n, m, k, x) = map(int, input().split())
	ans = k * n + m
	mod = x % ans
	if mod == 0 or mod > (k - 1) * n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k, x) = map(int, input().strip().split())
	tDays = n * k + m
	ntDays = n * (k - 1)
	rem = x % tDays
	if rem == 0 or (rem > ntDays and rem < tDays):
		print('YES')
	else:
		print('NO')


t = int(input())
for tc in range(t):
	(n, m, k, x) = map(int, input().split())
	a = k * n + m
	c = x % a
	if c == 0 or c > n * (k - 1):
		print('YES')
	else:
		print('NO')


try:
	t = int(input())
	for r in range(t):
		(n, m, k, x) = map(int, input().split())
		if x % (n * k + m) == 0:
			print('YES')
		elif x % (n * k + m) - n * (k - 1) > 0:
			print('YES')
		else:
			print('NO')
except:
	pass


for tc in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	mob = n + m
	mobdays = n * k + m
	val = x % mobdays
	if val == 0 or mobdays - mob < val < mobdays:
		print('YES')
	else:
		print('NO')


v = int(input())
vdx = []
for iiu in range(0, v):
	kl = str(input())
	uml = kl.split(' ')
	vxz = []
	for jjew in uml:
		vxz.append(int(jjew))
	vdx.append(vxz)
for iic in vdx:
	n = iic[0]
	m = iic[1]
	k = iic[2]
	x = iic[-1]
	ip = (k - 1) * n + n + m
	umit = x % ip
	if umit == 0:
		print('YES')
	else:
		yui = (k - 1) * n
		if yui >= umit and k != 1:
			print('NO')
		else:
			print('YES')


import math
tc = int(input())
for _ in range(tc):
	(n, m, k, x) = map(int, input().split())
	x = x % (k * n + m)
	if x == 0:
		print('YES')
	elif math.ceil(x / n) >= k:
		print('YES')
	else:
		print('NO')


import sys
for _ in range(int(sys.stdin.readline())):
	(n, m, k, x) = map(int, sys.stdin.readline().split())
	a = n * k + m
	b = x - x // a * a
	if k == 1 or b == 0:
		sys.stdout.write('YES\n')
	else:
		sys.stdout.write('YES\n' if b > (k - 1) * n else 'NO\n')


def mob(n, m, k, x):
	s = x // (n * k + m)
	a = x - s * (n * k + m)
	if k == 1 or a == 0:
		return 'YES'
	elif a > (k - 1) * n:
		return 'YES'
	else:
		return 'NO'
for _ in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	print(mob(n, m, k, x))


for _ in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	mod = n * k + m
	cur = x % mod
	if cur > n * k - n or not cur:
		print('YES')
	else:
		print('NO')


def main():
	T = int(input())
	for i in range(T):
		(n, m, k, x) = map(int, input().split(' '))
		rem = n * k + m
		mod = x % rem
		if mod == 0 or mod > (k - 1) * n:
			print('YES')
		else:
			print('NO')
main()


for _ in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	temp = x % (k * n + m)
	if temp == 0 or k == 1:
		print('YES')
	elif temp > (k - 1) * n:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	(n, m, k, x) = map(int, input().split())
	cycle = n * k + m
	if (x - 1) % cycle >= n * (k - 1):
		print('YES')
	else:
		print('NO')


test_cases = int(input(''))
while test_cases > 0:
	given_data = input()
	x = given_data.split()
	days = int(x[0])
	add_days = int(x[1])
	mob_year = int(x[2])
	giv_days = int(x[3])
	total = mob_year * days + add_days
	remaining = giv_days % total
	number = remaining - (mob_year - 1) * days
	if remaining == 0:
		print('YES')
	elif number > 0:
		print('YES')
	else:
		print('NO')
	test_cases -= 1


T = int(input())
for tc in range(T):
	(n, m, k, x) = map(int, input().split())
	mobYear = n * k + m
	x = x % mobYear
	if x == 0:
		print('YES')
	elif x <= n * (k - 1):
		print('NO')
	elif x <= mobYear:
		print('YES')


for _ in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	x %= k * n + m
	if 1 <= x <= (k - 1) * n:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(N, M, K, X) = [int(i) for i in input().split()]
	t = (K - 1) * N + N + M
	if X % t == 0 or X % t in range(t - N - M + 1, t):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(N, M, K, X) = map(int, input().split(' '))
	value = N * K + M
	left = value - (N + M)
	rem = X % value
	if rem > left or rem == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for ni in range(t):
	(n, m, k, x) = map(int, input().split())
	a1 = n * k + m
	a2 = n * (k - 1)
	a = x % a1
	if a2 < a < a1 or a == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, m, k, x) = [int(x) for x in input('').split()]
	cycle = k * n + m
	div = x % cycle
	if div == 0 or div > (k - 1) * n:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	b = [int(i) for i in input().split()]
	c = b[0] * b[2] + b[1]
	d = b[3] % c
	if b[0] * (b[2] - 1) < d < c or d == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, m, k, x) = [int(x) for x in input().split()]
	slot = x // (n * k + m)
	days = x - (n * k + m) * slot
	if k == 1 or days == 0:
		print('YES')
	elif days > (k - 1) * n:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m, k, x) = map(int, input().split())
	ct = 0
	ct = (k - 1) * n + m + n
	if x <= ct:
		if x <= ct - n - m:
			print('NO')
			continue
		else:
			print('YES')
			continue
	dev = x // ct
	ct = ct * dev
	ct = ct + (k - 1) * n + m + n
	days = x - dev * (n * k + m)
	if k == 1 or days == 0:
		print('Yes')
	elif x <= ct - n - m:
		print('NO')
	else:
		print('YES')


import math

def check(d, n, m, k, x):
	cal = d * n + d // k * m
	if cal >= x:
		return True
	return False

def ans(n, m, k, x):
	d = math.ceil(x / (n + m / k))
	if check(d - 1, n, m, k, x):
		if (d - 1) % k == 0:
			return 'YES'
		return 'NO'
	for i in range(0, k):
		if check(d + i, n, m, k, x):
			if (d + i) % k == 0:
				return 'YES'
			return 'NO'
test_cases = int(input())
while test_cases != 0:
	d = list(map(int, input().split()))
	print(ans(d[0], d[1], d[2], d[3]))
	test_cases -= 1


t = int(input())
for i in range(t):
	(n, m, k, x1) = map(int, input().split())
	x = n * k + m
	y = n * (k - 1)
	z = x1 % x
	if z == 0:
		print('YES')
	elif z - y > 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(x, B, y, D) = map(int, input().split())
	if D % (x * y + B) - x * (y - 1) > 0:
		print('YES')
	elif D % (x * y + B) == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m, k, x) = map(int, input().split(' '))
	d = n * k + m
	rem = x % d
	if rem == 0 or rem - n * (k - 1) > 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	(N, M, K, X) = map(int, input().split())
	slot = X // (N * K + M)
	days = X - slot * (N * K + M)
	if K == 1 or days == 0:
		print('YES')
	elif days > (K - 1) * N:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k, x) = [int(i) for i in input().split()]
	if k == 1:
		print('YES')
	else:
		days = n * k + m
		rem = x % days
		if rem == 0:
			print('YES')
		elif rem in range(1, n * (k - 1) + 1):
			print('NO')
		else:
			print('YES')


import math
n_test = int(input())
for i in range(0, n_test):
	(n, m, k, x) = map(int, input().split())
	l = x % (k * n + m)
	if l == 0 or l > (k - 1) * n:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m, k, x) = map(int, input().split())
	div = n * (k - 1)
	mod = x % (k * n + m)
	print('YES' if mod > div or mod == 0 else 'NO')


v = int(input())
for i in range(v):
	(a, b, c, d) = map(int, input().split())
	every_year = c * a + b
	mod = d % every_year
	if mod == 0 or mod > (c - 1) * a:
		print('YES')
	else:
		print('NO')