Problem: Ringo Mart, a convenience store, sells apple juice.  On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.  Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.  Note that each test case in this problem consists of T queries.

Submission attempts (in order):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def debug_print(s):
    pass
    # print(s, end="")

def solve2(A, B, C, D):
    def before_C(v):
        if v > C:
            tmp = v - ( (v - C) // B ) * B
            if tmp == C and tmp + B <= v:
                tmp += B
            return tmp
        else:
            return v
    if B > A:
        debug_print("(1)")
        return "No"
    if B > D:
        debug_print("(2)")
        return "No"
    if B <= C:
        debug_print("(3)")
        return "Yes"

    A = before_C(A)
    if B > A:
        debug_print("(4)")
        return "No"

    if A <= C:
        A -= B
        A += D

    seen = set()
    while True:
        A = before_C(A)
        if A < 0:
            return "No"
        if A <= C:
            A += D
        if A in seen:
            return "Yes"
        seen.add(A)

    return "unknown"

    gcd1 = gcd(B, D)
    gcd2 = gcd((A - B), (B - C))
    if gcd2 % gcd1 == 0:
        return "Yes"
    else:
        return "No"

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

    

def solve():
    A, B, C, D = map(int, input().split())
    return solve2(A, B, C, D)

    
T = int(input())
for t in range(T):
    print(solve())



#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#


#

#






# 


#


#



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


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





#     """
#     d = a
#     if b != 0:
#         d, y, x = extgcd(b, a % b)

#     else:
#         x = 1

#     return x, y, d


def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
#    if B - g + (A % g) > C:
    if (B - g + A) % g > C:
        return "No"
    else:
        return "Yes"


T = int(input())
for t in range(T):
    A, B, C, D = map(int, input().split())
    print(solve(A, B, C, D))
    



#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#




#
#

#






# 





# 


#
#


#



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


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


def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
    if B - g + (A % g) > C:
        return "No"
    else:
        return "Yes"


T = int(input())
for t in range(T):
    A, B, C, D = map(int, input().split())
    print(solve(A, B, C, D))
    



Verdicts: Wrong Answer

Wrong Answer

Accepted