Buggy python submission (verdict: Runtime Error):
from math import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')


Fixed submission:
from fractions import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
from collections import defaultdict
t = int(input())

# (b,c,d) -> {A -> No/Yes, ...}
memo = defaultdict(dict)
for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b:
        print('No')
        continue

    if d >= b and c+1 >= b:
        print('Yes')
        continue

    key = (b,c,d)
    if key in memo:
        for A, ans in memo[key].items():
            #print(a,A)
            if a in A:
                print(ans)
                continue

    A = set([a])
    while(True):
        if (a-c)%b == 0:
            x = (a-c)//b
        else:
            x = ceil((a-c)/b)
        if a-b*x < 0:
            print('No')
            memo[key][frozenset(A)] = 'No'
            break
        next_a = a-b*x+d
        if next_a < b:
            print('No')
            memo[key][frozenset(A)] = 'No'
            break
        if next_a in A:
            print('Yes')
            memo[key][frozenset(A)] = 'Yes'
            break
        A.add(next_a)
        if len(A) >= d:
            print('No')
            memo[key][frozenset(A)] = 'No'
            break
        a = next_a


Fixed submission:
from fractions import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b:
        print('No')
        continue

    if d >= b and c+1 >= b:
        print('Yes')
        continue

    A = set([a])
    while(True):
        #print(A)
        if (a-c)%b == 0:
            x = (a-c)//b
        else:
            x = ceil((a-c)/b)
        if a-b*x < 0:
            #print('No1')
            print('No')
            break
        next_a = a-b*x+d
        #print(next_a)
        if next_a < b:
            #print('No2')
            print('No')
            break
        if next_a in A:
            print('Yes')
            break
        A.add(next_a)
        if len(A) >= d:
            #print('No3')
            print('No')
            break
        a = next_a


Fixed submission:
from fractions import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')