Buggy python submission (verdict: Time Limit Exceeded):
def main():
  t = int(input())
  for _ in range(t):
    a, b, c, d = map(int, input().split())
    if (a < b or d < b):
      print("No")
      continue
    if (c >= b - 1):
      print("Yes")
      continue
  
    a %= b
    if a > c:
      print("No")
      continue
    d %= b
    if d == 0:
      print("Yes")
      continue
    if b % d != 0:
      print("No")
      continue
    for i in range(b // d):
      a = (a + d) % b
      if a > c:
        print("No")
        break
    else:
      print("Yes")
main()

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

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    #exception
    if a < b or d < b:
        print("No")
        continue

    if c >= b:
        print("Yes")
        continue

    g = gcd(d, b)
    print("Yes" if b - g + a % g <= c else "No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
def divisor(b):
  lst = []
  init = 2
  while b > 1:
    for i in range(init, int(b ** (1 / 2)) + 1):
      if b % 2 == 0:
        lst.append(i)
        lst.append(b // i)
        b //= i
        init = i
    else:
      break
  return set(lst)
def main():
  t = int(input())
  for _ in range(t):
    a, b, c, d = map(int, input().split())
    if (a < b or d < b):
      print("No")
      continue
    if (c >= b):
      print("Yes")
      continue
  
    a %= b
    if a > c:
      print("No")
      continue
    d %= b
    lst = defaultdict(bool)
    while True:
      a %= b
      if a > c:
        print("No")
        break
      if lst[a]:
        print("Yes")
        break
      lst[a] = True
      a += d
main()

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

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    #exception
    if a < b or d < b:
        print("No")
        continue

    if c >= b:
        print("Yes")
        continue

    g = gcd(d, b)
    print("Yes" if b - g + a % g <= c else "No")

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  t = int(input())
  for _ in range(t):
    a, b, c, d = map(int, input().split())
    if (a < b or d < b):
      print("No")
      continue
    if (c >= b):
      print("Yes")
      continue
  
    lst = []
    d %= b
    while True:
      a %= b
      if a > c:
        print("No")
        break
      if a in lst:
        print("Yes")
        break
      lst.append(a)
      a += d
main()

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

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    #exception
    if a < b or d < b:
        print("No")
        continue

    if c >= b:
        print("Yes")
        continue

    g = gcd(d, b)
    print("Yes" if b - g + a % g <= c else "No")

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  t = int(input())
  for _ in range(t):
    a, b, c, d = map(int, input().split())
    if (a < b or d < b):
      print("No")
      continue
    if (c >= b):
      print("Yes")
      continue
  
    lst = []
    while True:
      a %= b
      if a > c:
        print("No")
        break
      if a in lst:
        print("Yes")
        break
      lst.append(a)
      a += d
main()

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

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    #exception
    if a < b or d < b:
        print("No")
        continue

    if c >= b:
        print("Yes")
        continue

    g = gcd(d, b)
    print("Yes" if b - g + a % g <= c else "No")

Buggy python submission (verdict: Time Limit Exceeded):
t = int(input())
for _ in range(t):
  a, b, c, d = map(int, input().split())
  if (a < b or d < b):
    print("No")
    continue
  if (c >= b):
    print("Yes")
    continue

  lst = []
  while True:
    a %= b
    if a > c:
      print("No")
      break
    if a in lst:
      print("Yes")
      break
    lst.append(a)
    a += d

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

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    #exception
    if a < b or d < b:
        print("No")
        continue

    if c >= b:
        print("Yes")
        continue

    g = gcd(d, b)
    print("Yes" if b - g + a % g <= c else "No")