Buggy python submission (verdict: Time Limit Exceeded):
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    rec = [a]
    flag = False
    num = 0
    while True and num < 100000:
        if a < b:
            break
        else:
            a = a % b
        if a <= c:
            a += d
        else:
            break
        if a in rec:
            flag = True
            break
        num += 1
        rec.append(a)
    if flag:
        print("Yes")
    else:
        print("No")

Fixed submission:
T = int(input())


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


for i in range(T):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif d < b:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        g = gcd(b, d)
        if b - g + a % g > c:
            print('No')
        else:
            print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    rec = [a]
    flag = False
    num = 0
    while True and num < 10000:
        if a < b:
            break
        else:
            a = a % b
        if a <= c:
            a += d
        if a in rec:
            flag = True
            break
        num += 1
        rec.append(a)
    if flag:
        print("Yes")
    else:
        print("No")

Fixed submission:
T = int(input())


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


for i in range(T):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif d < b:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        g = gcd(b, d)
        if b - g + a % g > c:
            print('No')
        else:
            print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    rec = [a]
    flag = False
    num = 0
    while True and num < 100000:
        if a < b:
            break
        else:
            a = a % b
        if a <= c:
            a += d
        if a in rec:
            flag = True
            break
        num += 1
        rec.append(a)
    if flag:
        print("Yes")
    else:
        print("No")


Fixed submission:
T = int(input())


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


for i in range(T):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif d < b:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        g = gcd(b, d)
        if b - g + a % g > c:
            print('No')
        else:
            print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    rec = [a]
    flag = False
    num = 0
    while True and num < 100000:
        if a < b:
            break
        else:
            a = a % b
        if a <= c:
            a += d
        if a in rec:
            flag = True
            break
        num += 1
        rec.append(a)
    if flag:
        print("Yes")
    else:
        print("No")

Fixed submission:
T = int(input())


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


for i in range(T):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif d < b:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        g = gcd(b, d)
        if b - g + a % g > c:
            print('No')
        else:
            print('Yes')