Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())

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

  #dがbより小さければ減り続けるのでNo
  #aがbより小さければいきなり買えない
  if d<b or a<b:
    print('No')
    continue

  #cがb-1以上だと足りないときは常に補ってくれる
  if b-1<=c:
    print('Yes')
    continue
  
  #d補充した分からbずつ買って余りが出る、かつそれがアンラッキーゾーンより狭いと必ず買えない日が出てくる
  if d%b<b-c and d%b!=0:
    print('No')
    continue

  #在庫がc以上を保った最小の
  for j in range(c):
    if a>c:
      a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    else:
      if a==c:
        a = a-b
    if d%b!=0:
      if b%(d%b)==0 and b-(b-a)%(d%b)<=c:
        print('Yes')
        break
    a+=d
    if j==c-1:
      print('Yes')




Fixed submission:
import fractions
T = int(input())

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

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

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

  gcd=fractions.gcd(d,b)
  e=b-gcd+a%gcd
  if e>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())
  if d<b or a<b:
    print('No')
    continue
  if b-1<=c:
    print('Yes')
    continue
  if d%b<b-c and d%b!=0:
    print('No')
    continue
  for j in range(c):
    if a>c:
      a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    else:
      if a==c:
        a = a-b
    a+=d
    if j==c-1:
      print('Yes')




Fixed submission:
import fractions
T = int(input())

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

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

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

  gcd=fractions.gcd(d,b)
  e=b-gcd+a%gcd
  if e>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())
  if d<b or a<b:
    print('No')
    continue
  if b-1<=c:
    print('Yes')
    continue
  if d%b<b-c and  d%b!=0:
    print('No')
    continue
  visited=[]
  while True:
    if a>c:
      a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    elif a == c:
      if c in visited:
        print('Yes')
        break
      visited.append(a)
    else:
      a = a-b
      if a in visited:
        print('Yes')
        break
      visited.append(a)
    a+=d



Fixed submission:
import fractions
T = int(input())

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

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

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

  gcd=fractions.gcd(d,b)
  e=b-gcd+a%gcd
  if e>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())
  if d<b or a<b:
    print('No')
    continue
  if b-1<=c:
    print('Yes')
    continue
  if d%b<b-c and  d%b!=0:
    print('No')
    continue
  visited=[]
  while True:
    a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    elif a == c:
      if c in visited:
        print('Yes')
        break
      visited.append(a)
    else:
      a = a-b
      if a in visited:
        print('Yes')
        break
      visited.append(a)
    a+=d



Fixed submission:
import fractions
T = int(input())

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

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

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

  gcd=fractions.gcd(d,b)
  e=b-gcd+a%gcd
  if e>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())
  if d<b or a<b:
    print('No')
    continue
  if b-1<=c:
    print('Yes')
    continue
  visited=[]
  while True:
    a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    elif a == c:
      if c in visited:
        print('Yes')
        break
      visited.append(a)
    else:
      a = a-b
      if a in visited:
        print('Yes')
        break
      visited.append(a)
    a+=d



Fixed submission:
import fractions
T = int(input())

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

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

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

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