# Arup Guha
# 2/24/2024
# Solution to SER D1/D2 Problem K: Streets Behind

# Returns true if we can do this case, false otherwise.
def cando(n,k,a,b):

    # Can't even convert 1; how sad!
    if b*n < a*(n+1):
        return False

    # We're good.
    return True

# Simulate the process.
def sim(n,k,a,b):

    res = 0

    # While everyone isn't converted, go...
    while k > 0:

        # Do some math, this is the most we can convert in one turn.
        sub = (n*(b-a))//a

        # This is what n would be by the time we could convert more people.
        newn = a*(sub+1)//(b-a)
        if (a*(sub+1))%(b-a) != 0:
            newn += 1

        # This is how many times we can repeat our conversion and get exactly
        # sub number of people.
        numj = (newn-n)//sub

        # I only "speed step" if we're converting less than 1000 people, there
        # are more than 1000 people to convert and we have at least 1 "jump"
        # Theoretically, this is supposed to be a square root type check.
        # I just knew if we're subtracting more than 1000 a time, then no
        # more than a million iterations, so we're good.
        if sub < 1000 and k > 1000 and numj > 0:

            # We can do all of the conversions, so do them.
            if k - (numj*sub) >= 0:
                res += numj
                n += (numj*sub)
                k -= (numj*sub)

            # Be careful and convert until no more leisurely runners are left.
            else:

                # Just go to 0.
                numj = k//sub
                if k%sub != 0:
                    numj += 1
                res += numj;
                n += k
                k = 0

        # If the if isn't true it's good enough to simulate 1 step.
        else:
            res += 1
            n += sub
            k -= sub
            
    # Ta da!
    return res

# Run it!
nC = int(input())
for i in range(nC):

    # Get input.
    toks = input().split()
    n = int(toks[0])
    k = int(toks[1])
    a = int(toks[2])
    b = int(toks[3])

    # Get this out of the way.
    if not cando(n,k,a,b):
        print(-1)

    # Run the sim.
    else:
        print(sim(n,k,a,b))

        

