Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue
    while True:
        s = s%b
        if s > c:
            print('No')
            break
        s += d
        if s in mod_list:
            print('Yes')
            break
        mod_list.append(s)

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


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    s_list = []
    while True:
        if (s < b) or (b>d):
            print('No')
            break
        s = s%b
        s_list.append(s)
        if c < s < b:
            print('No')
            break

        s = s+d
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)


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


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    if (s < b) or (b>d):
        print('No')
        continue


    s_list = []
    while True:
        s_list.append(s)
        if s > b*2:
            s -= b*((s//b)-1)
            while s <= c:
                s+= c
        s -= b
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)


        if s <0:
            print('No')
            break
        if s <= c:
            s += d
            s_list.append(s)
            if s != s_list[-1]:
                if s in s_list:
                    print('Yes')
                    break


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


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    a, b, c, d = r[0], r[1], r[2], r[3]
    s = a


    s_list = []
    while True:
        s_list.append(s)


        if s > 100:
            s -= b*((s//b)-1)
            while s <= c:
                s+= c
        s -= b
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)


        if s <0:
            print('No')
            break
        if s != s_list[-1]:
            if s in s_list:
                print('Yes')
                break

        if s <= c:
            s += d
            s_list.append(s)
            if s != s_list[-1]:
                if s in s_list:
                    print('Yes')
                    break


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


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')