Vova is playing a computer game. There are in total $n$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $k$.

During each turn Vova can choose what to do:   If the current charge of his laptop battery is strictly greater than $a$, Vova can just play, and then the charge of his laptop battery will decrease by $a$;  if the current charge of his laptop battery is strictly greater than $b$ ($b<a$), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by $b$;  if the current charge of his laptop battery is less than or equal to $a$ and $b$ at the same time then Vova cannot do anything and loses the game. 

Regardless of Vova's turns the charge of the laptop battery is always decreases.

Vova wants to complete the game (Vova can complete the game if after each of $n$ turns the charge of the laptop battery is strictly greater than $0$). Vova has to play exactly $n$ turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.

Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 10^5$) — the number of queries. Each query is presented by a single line.

The only line of the query contains four integers $k, n, a$ and $b$ ($1 \le k, n \le 10^9, 1 \le b < a \le 10^9$) — the initial charge of Vova's laptop battery, the number of turns in the game and values $a$ and $b$, correspondingly.


-----Output-----

For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.


-----Example-----
Input
6
15 5 3 2
15 5 4 3
15 5 2 1
15 5 5 1
16 7 5 2
20 5 7 3

Output
4
-1
5
2
0
1



-----Note-----

In the first example query Vova can just play $4$ turns and spend $12$ units of charge and then one turn play and charge and spend $2$ more units. So the remaining charge of the battery will be $1$.

In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be $0$ after the last turn.

Difficulty: MEDIUM

Solutions:
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if k - n * a > 0:
		print(n)
	elif k - n * b <= 0:
		print(-1)
	elif k - n * a == 0:
		print(n - 1)
	else:
		print(n - ((n * a - k) // (a - b) + 1))


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
from math import ceil
n = c.cin()
for i in range(n):
	ini = c.cin()
	turns = c.cin()
	a = c.cin()
	b = c.cin()
	totala = a * turns
	dif = totala - ini + 1
	if dif <= 0:
		print(turns)
	else:
		red = ceil(dif / (a - b))
		if turns - red >= 0:
			print(turns - red)
		else:
			print(-1)


def main():
	import sys
	input = sys.stdin.readline

	def solve():
		(k, n, a, b) = map(int, input().split())
		if k <= n * b:
			print(-1)
			return
		l = 0
		r = n + 1
		while r - l != 1:
			m = l + r >> 1
			K = k - a * m
			if K <= 0 or K <= b * (n - m):
				r = m
			else:
				l = m
		print(l)
	for _ in range(int(input())):
		solve()
	return 0
main()


from math import ceil
q = int(input())
while q > 0:
	(k, n, a, b) = map(int, input().split())
	x = (k - b * n) / (a - b)
	if k - b * n <= 0:
		ans = -1
	else:
		ans = min(n, ceil(x) - 1)
	print(ans)
	q = q - 1


for i in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print(str('-1'))
	else:
		print(str(min((k - b * n - 1) // (a - b), n)))


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if k - n * b < 0:
		print(-1)
		continue
	if k - n * a > 0:
		print(n)
		continue
	diff = a - b
	c = math.ceil((n * a - k) / diff)
	if c * diff == n * a - k:
		c += 1
	print(n - c)


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	s1 = k - b
	if s1 % b == 0:
		s1 = s1 // b
	else:
		s1 = s1 // b + 1
	s2 = k - a
	if s2 % a == 0:
		s2 = s2 // a
	else:
		s2 = s2 // a + 1
	if s1 < n:
		print(-1)
	else:
		y = k - b * (s1 - 1)
		r = s1 - n
		z = y - b - 1 + r * b
		d = a - b
		z = z // d
		if z > s2:
			z = s2
		if z > n:
			z = n
		print(z)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
	ok = mn
	ng = mx
	while ok + 1 < ng:
		mid = (ok + ng) // 2
		if func(mid):
			ok = mid
		else:
			ng = mid
	return ok

def check(m):
	return a * m + b * (N - m) < K
for _ in range(INT()):
	(K, N, a, b) = MAP()
	res = bisearch_max(-1, N + 1, check)
	print(res)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k % b == 0:
		d0 = k // b - 1
	else:
		d0 = k // b
	if d0 < n:
		print(-1)
	else:
		t1 = k / a
		if k % a == 0:
			d1 = k // a - 1
		else:
			d1 = k // a
		if (k - b * n) % (a - b) == 0:
			d2 = (k - b * n) // (a - b) - 1
		else:
			d2 = (k - b * n) // (a - b)
		print(min(min(d1, n), min(d2, n)))


from sys import stdin
import math

def solve(tc):
	(k, n, a, b) = map(int, stdin.readline().split())
	if k <= b * n:
		print(-1)
		return
	r = (k - b * n) // (a - b)
	if (k - b * n) % (a - b) == 0:
		r -= 1
	print(min(r, n))
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


q = int(input())
for _ in range(q):
	(K, N, A, B) = map(int, input().split())
	if B * N >= K:
		print(-1)
	elif A * N < K:
		print(N)
	else:
		print(-(-(K - B * N) // (A - B)) - 1)


t = int(input())
for _ in range(t):
	(k, n, a, b) = [int(x) for x in input().split()]
	k -= 1
	if k < n * b:
		print(-1)
	else:
		print(min((k - n * b) // (a - b), n))


for f in range(int(input())):
	(k, n, a, b) = [int(i) for i in input().split()]
	k -= 1
	q = k - n * b
	if q < 0:
		print(-1)
	else:
		print(min(q // (a - b), n))


for case in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	if (k - 1) // b < n:
		print('-1')
		continue
	(l, r) = (0, n)
	while l <= r:
		mid = l + r >> 1
		if mid * a + (n - mid) * b < k:
			l = mid + 1
		else:
			r = mid - 1
	print(min(r, n))


q = int(input())
for kase in range(q):
	(k, n, a, b) = [int(x) for x in input().split()]
	if b * n >= k:
		print(-1)
	else:
		if (k - n * b) % (a - b) == 0:
			x = (k - n * b) // (a - b) - 1
		else:
			x = (k - n * b) // (a - b)
		print(min(n, x))


from math import *
q = int(input())
A = []
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	x = (k - n * b) / (a - b)
	x = ceil(x) - 1
	if x > n:
		x = n
	if x < 0:
		x = -1
	A.append(x)
for i in range(q):
	print(A[i])


import math
for i in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	c = (k - n * b) / (a - b)
	if c <= 0:
		print(-1)
	else:
		if math.floor(c) == c:
			c = int(c) - 1
		else:
			c = math.floor(c)
		print(min(c, n))


from math import ceil

def func(mid):
	x = k - mid * a
	p = n - mid
	if ceil((x - b) / b) >= p:
		return True
	else:
		return False
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k < n * b + 1:
		print(-1)
	else:
		an = 0
		up = n
		do = 0
		while up >= do:
			mid = (up + do) // 2
			if func(mid):
				do = mid + 1
				an = mid
			else:
				up = mid - 1
		print(an)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(k, n, a, b) = mp()
	if n * b >= k:
		print(-1)
		continue
	print(min(n, (k - n * b - 1) // (a - b)))


from sys import stdout, stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])

def bs(be, en, x):
	while be < en:
		mid = (be + en + 1) // 2
		val = x - mid * a
		if val - b * (n - mid) < 0:
			en = mid - 1
		else:
			be = mid
	return be
ans = []
for i in range(int(input())):
	(k, n, a, b) = arr_inp(1)
	k -= 1
	if k // b < n:
		ans.append(str(-1))
	else:
		num = k // a
		ans.append(str(min(bs(0, num, k), n)))
stdout.write('\n'.join(ans))


for j in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
	else:
		s = k - b * n - 1
		t = s // (a - b)
		print(min(t, n))


q = int(input())
M = []
for count in range(q):
	M += [[int(i) for i in input().split()]]
for arr in M:
	k = arr[0]
	n = arr[1]
	a = arr[2]
	b = arr[3]
	if b * n >= k:
		print(-1)
	elif a * n < k:
		print(n)
	else:
		print(n - (a * n - k) // (a - b) - 1)


t = int(input())
for baka in range(t):
	(k, n, a, b) = list(map(int, input().split()))
	if k - n * b <= 0:
		print(-1)
	else:
		x = k - n * b
		if x % (a - b) == 0:
			print(min(n, (k - n * b) // (a - b) - 1))
		else:
			print(min(n, (k - n * b) // (a - b)))


import sys
input_ = sys.stdin.readline
q = int(input_())
for _ in range(q):
	(k, n, a, b) = map(int, input_().strip().split())
	if n * b >= k:
		print(-1)
	else:
		remain = k - n * b
		if remain % (a - b) == 0:
			quotient = remain // (a - b) - 1
		else:
			quotient = remain // (a - b)
		answer = min(n, quotient)
		print(answer)


q = int(input())
for l in range(q):
	(k, n, a, b) = input().split(' ')
	k = int(k)
	b = int(b)
	a = int(a)
	n = int(n)
	chance = int(k / b)
	if k % b == 0:
		chance -= 1
	if chance < n:
		print(-1)
	else:
		chance = int(k / a)
		if k % a == 0:
			chance -= 1
		if chance >= n:
			print(n)
			continue
		beg = 0
		end = chance
		while beg <= end:
			mid = int((beg + end) / 2)
			need = mid * a + (n - mid) * b
			need1 = (mid + 1) * a + (n - (mid + 1)) * b
			if need >= k:
				end = mid - 1
			elif need < k and need1 < k:
				beg = mid + 1
			else:
				print(mid)
				break


import sys
import math
q = int(input())
for t in range(q):
	(k, n, a, b) = map(int, input().split())
	tempMaxB = k / b
	if tempMaxB == int(tempMaxB):
		tempMaxB -= 1
	if int(tempMaxB) >= n:
		tempMaxA = (k - b * n) / (a - b)
		if tempMaxA == int(tempMaxA):
			print(min(int(tempMaxA - 1), n))
		else:
			print(min(int(tempMaxA), n))
	else:
		print(-1)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	extra = k - n * b - 1
	if extra < 0:
		print(-1)
		continue
	ans = min(n, extra / (a - b))
	print(int(ans))


q = int(input())
for query in range(q):
	(a, b, c, d) = map(int, input().split())
	if b * d >= a:
		print(-1)
	else:
		print(min(b, (a - b * d - 1) // (c - d)))


q = int(input())
L = lambda : list(map(int, input().split()))
import math
for quer in range(q):
	(k, n, a, b) = L()
	if k / b <= n:
		print(-1)
		continue
	nm = math.ceil((k - b * n) / (a - b))
	print(min(nm - 1, n))


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)

def print_list(l):
	print(' '.join(map(str, l)))
q = read_int()
for _ in range(q):
	(k, n, a, b) = read_int_list()
	if k > n * a:
		print(n)
		continue
	if k <= n * b:
		print(-1)
		continue
	ans = (k - n * b) / (a - b)
	if ans == int(ans):
		print(int(ans) - 1)
	else:
		print(int(ans))


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import sys
import operator
from decimal import Decimal
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def main():
	for _ in range(int(input())):
		(k, n, a, b) = [int(i) for i in input().split()]
		k -= 1
		p = n * b
		if k < p:
			print(-1)
		else:
			print(min((k - p) // (a - b), n))
main()


n = int(input())
for _ in range(n):
	(a, b, c, d) = map(int, input().split())
	if a - b * c > 0:
		print(b)
	else:
		t = (b * c - a) // (c - d) + 1
		if b - t >= 0:
			print(b - t)
		else:
			print(-1)


import math
_DEBUG = True
num_of_test = int(input())

def solve(k, n, a, b):
	if n * b >= k:
		return -1
	if k > n * a:
		return n
	floor_val = math.floor((k - b * n) / (a - b))
	if (k - b * n) % (a - b) == 0:
		return floor_val - 1
	return floor_val
for test_num in range(1, num_of_test + 1):
	(k, n, a, b) = map(int, input().split())
	solution = solve(k, n, a, b)
	print(solution)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
		continue
	print(max(0, min(n, (k - n * b - 1) // (a - b))))


for z in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k - n * b <= 0:
		print(-1)
		continue
	(low, high) = (0, n)
	while low != high:
		mid = low + high + 1 >> 1
		if k - (mid - 1) * a > a and k - mid * a - (n - mid) * b > 0:
			low = mid
		else:
			high = mid - 1
	print(low)


from sys import stdin, stdout
import string
input = stdin.readline

def main():
	t = int(input())
	for i in range(t):
		(k, n, a, b) = map(int, input().split())
		if (k - 1) // b < n:
			print(-1)
			continue

		def f(num):
			num2 = k - a * num
			if num2 < 1:
				return 1
			if (num2 - 1) // b < n - num:
				return 1
			return 0
		(l, r) = (0, n + 1)
		m = (l + r) // 2
		while l + 1 < r:
			if f(m):
				r = m
			else:
				l = m
			m = (l + r) // 2
		print(l)
main()


t = int(input())
while t > 0:
	(k, n, a, b) = map(int, input().split())
	if k < n * b + 1:
		print(-1)
	else:
		gap = k - (n * b + 1)
		c = a - b
		print(min(n, gap // c))
	t -= 1


def check(num):
	m = k
	m -= a * num
	m -= b * max(0, n - num)
	if m > 0:
		return True
	return False
for nt in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	low = 0
	high = k // a + 1
	while low < high:
		mid = (low + high) // 2
		if check(mid):
			low = mid + 1
		else:
			high = mid - 1
	if check(low):
		print(min(n, low))
	else:
		print(min(n, low - 1))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	(k, n, a, b) = inpl()
	if b * n >= k:
		print(-1)
		continue
	ok = 0
	ng = n + 1

	def sol(x):
		now = a * x + b * (n - x)
		return True if now < k else False
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if sol(mid):
			ok = mid
		else:
			ng = mid
	print(ok)


t = int(input())
for T in range(t):
	(k, n, a, b) = [int(x) for x in input().split()]
	n1 = n
	(jp, p) = (0, 0)
	c = 0
	if k <= n * b:
		print('-1')
	elif k > n * a:
		print(n)
	else:
		lb = -1
		ub = n + 1
		mid = 0
		while ub > lb + 1:
			mid = (lb + ub) // 2
			if mid * a + (n - mid) * b < k:
				lb = mid
			else:
				ub = mid
		print(lb)


for q in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
	else:
		l = 0
		r = 10 ** 9
		while l + 1 < r:
			x = (l + r) // 2
			if (k - x * a - 1) // b + x >= n:
				l = x
			else:
				r = x
		print(min(n, l))


q = int(input())
while q:
	q -= 1
	(k, n, a, b) = map(int, input().split())
	ans = k - n * b
	if ans % (a - b) != 0:
		ans = ans // (a - b) + 1
	else:
		ans //= a - b
	if ans <= 0:
		print(-1)
	else:
		ans -= 1
		if ans > n:
			ans = n
		print(ans)


import sys, math

def computer_game(k, n, a, b):
	return -1 if n * b >= k else min(int((k - b * n - 1) / (a - b)), n)
input_ = sys.stdin.read().split('\n')[1:-1]
for i in range(len(input_)):
	(k, n, a, b) = map(int, input_[i].split(' '))
	print(computer_game(k, n, a, b))


q = int(input())
result = [0] * q
for i in range(q):
	(k, n, a, b) = [int(x) for x in input().split(' ')]
	dif = a - b
	k = k - n * b
	if k <= 0:
		result[i] = -1
		continue
	else:
		k -= 1
		k = k // dif
		result[i] = min(k, n)
for i in result:
	print(i)


def solve(k, n, a, b):
	k -= 1
	dif = a - b
	min_to_win = b * n
	if k < b * n:
		return -1
	elif k == b * n:
		return 0
	else:
		x_possible = (k - b * n) // (a - b)
		if x_possible > n:
			return n
		return x_possible

def game_run():
	no_querries = int(input())
	out = []
	for i in range(no_querries):
		in_raw = input().split()
		list_arg = [int(x) for x in in_raw]
		out.append(solve(list_arg[0], list_arg[1], list_arg[2], list_arg[3]))
	for i in range(len(out)):
		print(out[i])
game_run()


num = int(input())
Ans = []
for i in range(num):
	(k, n, a, b) = [int(a) for a in input().split()]
	diff = a - b
	max_n = (k - 1) // b
	mag_a = k - 1 // a
	if max_n < n:
		Ans.append(-1)
	elif n * a < k - 1:
		Ans.append(n)
	elif max_n == n and (max_n - 1) * b + a > k - 1:
		Ans.append(0)
	else:
		diff = a - b
		max_b = n
		diff2 = (k - max_b * b - 1) // diff
		Ans.append(diff2)
for i in Ans:
	print(i)


t = int(input(''))
for _ in range(t):
	(n, k, a, b) = map(int, input().split())
	if k * a < n:
		print(k)
		continue
	elif n <= k * b:
		print(-1)
		continue
	else:
		a -= b
		l = n - b * k
		if l % a == 0:
			print(l // a - 1)
		else:
			print(l // a)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
from collections import deque
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(k, n, a, b) = map(int, input().split())
		if b * n >= k:
			print(-1)
		else:
			print(min(math.ceil((k - n * b) / (a - b)) - 1, n))
main()


tests = int(input())
for test in range(tests):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
	else:
		print(min(n, (k - n * b - 1) // (a - b)))


q = int(input())
for _ in range(q):
	(k, n, a, b) = [int(p) for p in input().split()]
	x = (k - b * n) / (a - b)
	if x <= 0:
		print(-1)
	elif int(x) == x:
		print(min(int(x) - 1, n))
	else:
		print(min(int(x), n))


import sys

class CComputerGame:

	def solve(self):
		import math
		q = int(input())
		for _ in range(q):
			(k, n, a, b) = [int(_) for _ in input().split()]
			jp = math.ceil((k - a) / a)
			r = k - a * jp
			pc = math.ceil((r - b) / b)
			if (k - 1) // b >= n:
				print(min((k - 1 - n * b) // (a - b), n))
			else:
				print(-1)
solver = CComputerGame()
input = sys.stdin.readline
solver.solve()


q = int(input())
ans = []
for w in range(q):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		ans.append(-1)
		continue
	l = 0
	r = n + 1
	while r - l > 1:
		m = (r + l) // 2
		ka = m
		kb = n - m
		if ka * a + kb * b < k:
			l = m
		else:
			r = m
	ans.append(l)
for i in range(q):
	print(ans[i])


q = int(input())
for it in range(q):
	(k, n, a, b) = map(int, input().split())
	t1 = (k - 1 - a) // a
	rem = k - a * (t1 + 1)
	if rem > b:
		t2 = (rem - 1) // b
	else:
		t2 = 0
	t3 = (k - 1) // b
	if max(t3, t1 + 1 + t2) < n:
		print(-1)
	else:
		print(min((k - 1 - b * n) // (a - b), n, t1 + 1))


q = int(input())
s = 0
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	s = 0
	k0 = k
	if k <= n * b:
		print(-1)
	else:
		print(min((k - n * b - 1) // (a - b), n))


import sys
import math
q = int(sys.stdin.readline())
for _ in range(q):
	(k, n, a, b) = map(int, sys.stdin.readline().split())
	c = 0
	c = k - n * a
	if c > 0:
		print(n)
	else:
		diff = a - b
		turns = math.ceil(abs((-c + 1) / diff))
		if turns > n:
			print(-1)
		else:
			print(n - turns)


from math import ceil
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	c = k - n * a
	if c > 0:
		print(n)
	else:
		diff = a - b
		trns = ceil((1 - c) / diff)
		if trns > n:
			print(-1)
		else:
			print(n - trns)


for q in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	t = k - b * n
	if t <= 0:
		print(-1)
	else:
		print(min((t - 1) // (a - b), n))


import sys
input = sys.stdin.buffer.readline
import math
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	t = k - n * b
	if t <= 0:
		print(-1)
	else:
		(q, r) = divmod(t, a - b)
		if r != 0:
			if q <= n:
				print(q)
			else:
				print(n)
		elif q - 1 <= n:
			print(q - 1)
		else:
			print(n)


q = int(input())
for _ in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	val = n
	while a * val + b * (n - val) >= k:
		if val < 0:
			val = -1
			break
		diff = a * val + b * (n - val) - k
		if diff == 0:
			val -= 1
			break
		count = diff // (a - b)
		if count == 0:
			val -= 1
		else:
			val -= count
	if val < 0:
		val = -1
	print(val)


def check(k, n, a, b, jp):
	r = k - jp * a
	if r <= 0:
		return False
	pac = r // b - 1 if r % b == 0 else r // b
	if jp + pac >= n:
		return True
	return False
nq = int(input())
for _ in range(nq):
	l = list(map(int, input().strip().split()))
	k = l[0]
	n = l[1]
	a = l[2]
	b = l[3]
	pac = k // b - 1 if k % b == 0 else k // b
	if pac < n:
		print(-1)
		continue
	jpmin = 0
	jpmax = k // a + 1
	while jpmin < jpmax - 1:
		m = (jpmin + jpmax) // 2
		if check(k, n, a, b, m):
			jpmin = m
		else:
			jpmax = m
	if jpmin > n:
		print(n)
	else:
		print(jpmin)


q = int(input())
vetres = []
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	aux = (k - n * b - 1) // (a - b)
	if k <= n * b:
		vetres.append(-1)
	elif aux < n:
		vetres.append(aux)
	else:
		vetres.append(n)
print(*vetres, sep='\n')


a = int(input())
for i in range(a):
	(z, x, n, m) = list(map(int, input().split()))
	if x * m >= z:
		print(-1)
	else:
		print(min((z - m * x - 1) // (n - m), x))


import sys
input = sys.stdin.buffer.readline
from math import *
t = int(input())
while t:
	t -= 1
	(k, n, a, b) = map(int, input().split())
	(mov1, mov2) = [0] * 2
	var = k
	if k % a == 0:
		mov1 += k // a - 1
		k = a
	else:
		mov1 += k // a
		k = k % a
	if mov1 >= n:
		print(n)
	elif var - b * n > 0:
		turn = int(ceil((-(var - a * n) + 1) / (a - b)))
		print(n - turn)
	else:
		print('-1')


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
		continue
	l = 0
	h = n
	while l < h:
		m = (l + h) // 2
		f = m * a + (n - m) * b
		if f >= k:
			h = m - 1
		else:
			l = m
		if h == l + 1:
			if h * a + (n - h) * b < k:
				l = h
			break
	print(l)


import math
import operator
T = int(input())
while T != 0:
	T -= 1
	(n, k, a, b) = map(int, input().split())
	if b * k >= n:
		print(-1)
	elif n - a * ((n - b * k) // (a - b)) - (k - (n - b * k) // (a - b)) * b == 0 and (n - b * k) // (a - b) > 0:
		print(min(k, (n - b * k) // (a - b) - 1))
	else:
		print(min(k, (n - b * k) // (a - b)))


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
q = rint()
for _ in range(q):
	(k, n, a, b) = rints()
	if k - n * b < 1:
		print(-1)
	else:
		k -= n * b
		print(min(n, (k - 1) // (a - b)))


import math
t = int(input())
for _ in range(0, t):
	(c, n, a, b) = list(map(int, input().split()))
	r = c - a * n
	d = a - b
	if r > 0:
		print(n)
		continue
	else:
		s = abs(r) // d + 1
		if s > n:
			print(-1)
		else:
			print(n - s)


def valid(xyz):
	if a * xyz + b * (n - xyz) < k:
		return True
	return False
q = int(input())
for j in range(q):
	(k, n, a, b) = map(int, input().split())
	x = -1
	i = n + 1
	while i >= 1:
		while valid(i + x) and i + x <= n:
			x += i
		i //= 2
	print(x)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	ans = []
	if k <= n * b:
		print(-1)
	else:
		high = n
		low = 0
		while high >= low:
			mid = (high + low) // 2
			if mid * a + (n - mid) * b < k:
				low = mid + 1
				ans.append(mid)
			else:
				high = mid - 1
		if ans:
			print(max(ans))
		else:
			print(0)


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	nt = 0
	x = 0
	if k % b == 0:
		x = 1
	if k // b - x >= n:
		nt = (k - n * b) / (a - b)
		if nt * 10 % 10 == 0:
			nt -= 1
			nt = int(nt)
		else:
			nt = int(nt)
		print(min(nt, n))
	else:
		print(-1)


def checkifpossible(k, n, b):
	return k - n * b > 0

def numberofturns(k, n, a, b):
	if checkifpossible(k, n, b):
		return min(n, int(n - (k - 1 - n * a) / (b - a)))
	else:
		return -1

def main():
	Q = int(input())
	for _ in range(Q):
		(k, n, a, b) = map(int, input().split(' '))
		print(numberofturns(k, n, a, b))
main()


import os

def _f(k, n, a, b):
	if b * n >= k:
		return -1
	if n * a < k:
		return n
	r = (k - b * n) / (a - b)
	if r == int(r):
		r = int(r) - 1
	else:
		r = int(r)
	if r < 0:
		return -1
	else:
		return r

def f(k, n, a, b):
	return _f(k, n, a, b)
if os.environ.get('DEBUG', False):
	print(f'{f(15, 5, 3, 2)} = 4')
	print(f'{f(15, 5, 4, 3)} = -1')
	print(f'{f(15, 5, 2, 1)} = 5')
	print(f'{f(15, 5, 5, 1)} = 2')
	print(f'{f(16, 7, 5, 2)} = 0')
	print(f'{f(20, 5, 7, 3)} = 1')
else:
	q = int(input())
	for i in range(q):
		(k, n, a, b) = list(map(int, input().split()))
		print(f(k, n, a, b))


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print(-1)
		continue
	e = min([n, (k - b * n - 1) // (a - b)])
	print(e)


for n in range(int(input())):
	(lvl, tot, a, b) = map(int, input().split())
	if tot * b >= lvl:
		print(-1)
		continue
	hi = tot
	lo = 0
	res = 0
	while hi >= lo:
		justpl = (hi + lo) // 2
		u = justpl * a + (tot - justpl) * b
		if justpl * a + (tot - justpl) * b < lvl:
			lo = justpl + 1
			res = justpl
		else:
			hi = justpl - 1
	print(res)


q = int(input())
while q:
	(k, n, a, b) = list(map(int, input().split()))
	temp = int(k - 1 - n * b)
	ans = int(temp / (a - b))
	if ans > n:
		ans = n
	elif temp < 0:
		ans = -1
	print(ans)
	q -= 1


query_num = int(input())
for i in range(query_num):
	(k, n, a, b) = map(int, input().split())
	if k // b < n or (k // b == n and k % b == 0):
		print(-1)
		continue
	gap = a - b
	right = k - b * n
	turns = (right - 1) // gap
	if turns >= n:
		print(n)
	else:
		print(turns)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		print(-1)
	else:
		l = 0
		r = n
		while l <= r:
			mid = (l + r) // 2
			val = mid * (a - b) + b * n
			if val < k:
				ans = mid
				l = mid + 1
			else:
				r = mid - 1
		print(ans)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	n1 = n2 = 0
	if k - b * n < 0:
		print('-1')
	elif k - a * n > 0:
		print(n)
	else:
		d = k - n * b - 1
		e = a - b
		print(d // e)


q = int(input())
for i in range(q):
	(k, n, a, b) = [int(x) for x in input().split()]
	t = k // b
	if k - (t - 1) * b <= b:
		t -= 1
	if t < n:
		print(-1)
	else:
		p = (k - b * n - 1) // (a - b)
		print(min(p, n))


for q in range(int(input())):
	(k, n, a, b) = map(int, input().split(' '))
	rem = k - n * b
	if rem <= 0:
		print(-1)
	else:
		val = (rem - 1) // (a - b)
		if val > n:
			print(n)
		else:
			print(val)


def getInts():
	return [int(x) for x in input().strip().split()]
t = int(input())
for _ in range(t):
	(k, n, a, b) = getInts()
	if k <= n * b:
		print(-1)
	else:
		print(min(n, (k - n * b - 1) // (a - b)))


import math
import sys
q = int(next(sys.stdin))
for _ in range(q):
	(k, n, a, b) = map(int, next(sys.stdin).split(' '))

	def cons(s):
		return a * s + (n - s) * b
	if cons(0) >= k:
		print(-1)
		continue
	left = 0
	right = n
	m = 0
	while abs(right - left) > 1:
		m = math.ceil((right + left) / 2)
		if cons(m) >= k:
			right = m
		else:
			left = m
	if cons(right) < k:
		print(right)
	else:
		print(left)


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	c = k - n * a
	diff = a - b
	if math.ceil((-c + 1) / diff) > n:
		print(-1)
	elif n - math.ceil((-c + 1) / diff) > n:
		print(n)
	else:
		print(n - math.ceil((-c + 1) / diff))


from sys import stdin, stdout
q = int(stdin.readline())
for _ in range(q):
	(k, n, a, b) = [int(x) for x in stdin.readline().split()]
	stdout.write(f'{(-1, min((k - 1 - n * b) // (a - b), n))[k - n * b > 0]}\n')


import math

def b_search(k, n, a, b):
	low = 0
	high = n
	while low < high:
		mid = low + math.ceil((high - low) / 2)
		if k - (n - mid) * b <= b:
			high = mid - 1
		elif k - (n - mid) * b - mid * a <= 0:
			high = mid - 1
		else:
			low = mid
	return low
q = int(input())
for x in range(q):
	[k, n, a, b] = [int(i) for i in input().split()]
	if k - b * n <= 0 or k - (n - 1) * b <= b:
		print(-1)
	else:
		print(b_search(k, n, a, b))


def check(k, n, a, b, by_a):
	by_b = n - by_a
	if b * by_b + a * by_a < k and by_b >= 0 and (by_a + by_b <= n):
		return True
	else:
		return False
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if k - n * b <= 0:
		print(-1)
	else:
		l = 0
		r = n + 1
		ma = 0
		while l != r:
			m = (l + r) // 2
			if check(k, n, a, b, m) and m > ma:
				l = m
				ma = m
			else:
				r = m
		print(ma)


q = int(input())
for i in range(q):
	x = [int(i) for i in input().split()]
	k = x[0]
	n = x[1]
	a = x[2]
	b = x[3]
	k = k - n * a
	if k > 0:
		print(n)
	else:
		k = -k + 1
		diff = a - b
		turns = (k + diff - 1) // diff
		if turns > n:
			print(-1)
		else:
			print(n - turns)


import math

def z(k, n, a, b):
	r = k - n * a
	s = math.ceil((1 - r) / (a - b))
	if s > n:
		return -1
	else:
		return min(n - s, n)
t = int(input())
while t > 0:
	(k, n, a, b) = map(int, input().split())
	print(z(k, n, a, b))
	t -= 1


t = int(input())
while t > 0:
	(k, n, a, b) = map(int, input().split())
	p = a - b
	if b * n >= k:
		ans = -1
	else:
		k = k - 1
		x = k - b * n
		ans = min(n, x // (a - b))
	print(ans)
	t -= 1


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
	else:
		mod = k - n * b - 1
		d = a - b
		if mod // d > n:
			print(n)
		else:
			print(mod // d)


q = int(input())
for i in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	ma = (k - 1) // a
	mb = (k - 1) // b
	if mb < n:
		print(-1)
		continue
	c = n * b
	k -= c
	if k < 0:
		print(-1)
		continue
	e = a - b
	print(min((k - 1) // e, n))


def solve(k, n, a, b):
	turn_a = 0
	turn_b = 0
	rm = 0
	turn_b = k // b
	rm = k % b
	if turn_b >= n:
		if turn_b == n and rm == 0:
			return -1
		rm += (turn_b - n) * b
		turn_b -= turn_b - n
	elif turn_b < n:
		return -1
	if rm % (a - b) == 0:
		rm -= 1
	ans = rm // (a - b)
	if ans <= n:
		return ans
	return n
q = int(input())
for _ in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	print(solve(k, n, a, b))


import math
n = int(input())
for i in range(n):
	(k, n, a, b) = map(int, input().split())
	if k - n * b < 1:
		print(-1)
	elif n * a < k:
		print(n)
	else:
		u = n * a
		g = a - b
		t = u - k
		l = math.ceil(t / g)
		if t % g == 0:
			print(n - l - 1)
		else:
			print(n - l)


nr_tests = int(input())
while nr_tests:
	print
	(k, n, a, b) = list(map(int, input().split()))
	lost = False
	if k <= n * b:
		print(-1)
		nr_tests -= 1
		continue
	else:
		aux = (k - n * b - 1) // (a - b)
		if aux < n:
			print(aux)
		else:
			print(n)
	nr_tests -= 1


def check(p):
	if p * a + (n - p) * b < k:
		return True
	return False
query = int(input())
for _ in range(query):
	(k, n, a, b) = map(int, input().split())
	x = -1
	w = n + 1
	while w > 0:
		while check(w + x) and w + x <= n:
			x += w
		w //= 2
	print(x)


f = int(input())
for i in range(f):
	q = input()
	(s, n, a, b) = q.split()
	s = int(s)
	n = int(n)
	a = int(a)
	b = int(b)
	if s - b * n > 0:
		o = (s - b * n - 1) // (a - b)
		if o > n:
			print(n)
		else:
			print(o)
	else:
		print(-1)


def probC(k, n, a, b):
	if n * b >= k:
		return -1
	else:
		mid = (0 + n) / 2
		start = 0
		end = n
		while start <= end:
			mid = int((start + end) / 2)
			x = mid * a + (n - mid) * b
			if x == k - 1:
				return mid
			elif x < k - 1:
				start = mid + 1
			else:
				end = mid - 1
		if (mid + 1) * a + (n - mid - 1) * b < k and mid + 1 <= n:
			return mid + 1
		elif mid * a + (n - mid) * b < k:
			return mid
		elif mid - 1 >= 0:
			return mid - 1
		else:
			return 0
q = int(input())
for i in range(q):
	(k, n, a, b) = input().split()
	n = int(n)
	k = int(k)
	a = int(a)
	b = int(b)
	print(probC(k, n, a, b))


def binary_search(n, a, b, k):
	left = 0
	right = n + 1
	while left < right - 1:
		middle = (left + right) // 2
		if middle * a + (n - middle) * b >= k:
			right = middle
		else:
			left = middle
	if left > -1:
		return left
	else:
		return -1
q = int(input())
for i in range(q):
	arr = list(map(int, input().split()))
	(k, n, a, b) = (arr[0], arr[1], arr[2], arr[3])
	if b * n >= k:
		print(-1)
	else:
		ans = binary_search(n, a, b, k)
		print(ans)


q = int(input())
while q > 0:
	(k, n, a, b) = list(map(int, input().split()))
	x = (k - n * b) // (a - b)
	y = 1 if (k - n * b) % (a - b) == 0 else 0
	if k - n * b <= 0:
		print(-1)
	elif n - x < 0:
		print(n)
	elif n - x == 0:
		print(n - y)
	else:
		print(x - y)
	q = q - 1


for ii in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	ans = (k - b * n - 1) // (a - b)
	if k - b * n - 1 < 0:
		print(-1)
	else:
		print(min(ans, n))


SS = []
a = int(input())
for i in range(a):
	(k, n, a, b) = map(int, input().split())
	k -= n * b
	if k > 0:
		ll = k // (a - b)
		if k % (a - b) == 0:
			ll -= 1
		SS.append(min(ll, n))
	else:
		SS.append(-1)
for s in SS:
	print(s)


import sys
import math

def getAndParseInt(num=1):
	string = sys.stdin.readline().strip()
	if num == 1:
		return int(string)
	else:
		return [int(part) for part in string.split()]

def getAndParseString(num=1, delim=' '):
	string = sys.stdin.readline().strip()
	if num == 1:
		return string
	else:
		return [part for part in string.split(delim)]

def findSol(k, n, a, b):
	start = 0
	end = n
	mid = 0
	while start <= end:
		mid = (start + end) // 2
		total = mid * a + (n - mid) * b
		if total >= k:
			end = mid - 1
		elif mid == n or (mid + 1) * a + b * (n - mid - 1) >= k:
			break
		else:
			start = mid + 1
	if mid * a + (n - mid) * b < k:
		return mid
	else:
		return -1
q = getAndParseInt()
for i in range(q):
	(k, n, a, b) = getAndParseInt(2)
	print(findSol(k, n, a, b))


q = int(input())
for _ in range(q):
	(k, n, a, b) = [int(i) for i in input().split()]
	temp = k // b
	rem = k % b
	if temp == n and rem == 0:
		print(-1)
	elif temp < n:
		print(-1)
	else:
		tot = k - 1
		sub = b * n
		tot -= sub
		div = a - b
		ans = tot // div
		if ans > n:
			ans = n
		print(ans)


from math import ceil
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if k // b < n or (k // b == n and k % b == 0):
		print(-1)
		continue
	x = ceil((k - b * n) / (a - b)) - 1
	if x > n:
		x = n
	print(x)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	r = n * b
	diff = k - r
	if diff <= 0:
		print(-1)
		continue
	elif (diff - 1) // (a - b) <= n:
		print((diff - 1) // (a - b))
	else:
		print(n)


t = int(input())
for yo in range(t):
	l = input()
	l = l.split(' ')
	b = int(l[0])
	b -= 1
	n = int(l[1])
	a = int(l[2])
	b1 = int(l[3])
	a -= b1
	b -= n * b1
	val = b // a
	if b < 0:
		print(-1)
	elif val > n:
		print(n)
	else:
		print(val)


import math
q = int(input())
for _ in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	c = k - n * a
	if c > 0:
		print(n)
		continue
	delta = a - b
	change = math.ceil((-c + 1) / delta)
	if change > n:
		print(-1)
		continue
	print(n - change)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k - n * b <= 0:
		print(-1)
	elif (k - n * b) % (a - b) == 0:
		print(min(n, (k - n * b) // (a - b) - 1))
	else:
		print(min((k - n * b) // (a - b), n))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	s = b * n
	if s >= k:
		print(-1)
	else:
		print(min((k - s - 1) // (a - b), n))


import math

def Computer_Game(k, n, a, b):
	if b * n >= k:
		return -1
	else:
		return min(n, math.ceil((k - n * b) / (a - b) - 1))
q = int(input())
C = []
for i in range(q):
	A = []
	for x in input().split():
		A.append(int(x))
	C.append(Computer_Game(A[0], A[1], A[2], A[3]))
for i in C:
	print(i)


import math, bisect
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	(k, n, a, b) = M()
	k -= n * a
	if k > 0:
		print(n)
	else:
		k = -k
		d = a - b
		t = (k + d) // d
		if t > n:
			print(-1)
		else:
			print(n - t)


import math
t = int(input())
for i in range(t):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
	else:
		maxa = math.ceil((k - a) / a)
		maxi = maxa
		mini = 0
		result = 0
		while mini <= maxi:
			val = (mini + maxi) // 2
			temp = k - val * a - b
			maxb = math.ceil(temp / b) if temp >= 0 else 0
			if val + maxb >= n:
				result = val
				mini = val + 1
			else:
				maxi = val - 1
		print(min(n, result))


import math
q = int(input())
for i in range(q):
	l = [int(x) for x in input().split()]
	k = j = l[0]
	n = l[1]
	a = l[2]
	b = l[3]
	count1 = 0
	count2 = 0
	count3 = 0
	x = math.ceil((b * n - k) / (b - a)) - 1
	if x >= 0:
		print(min(n, x))
	else:
		print(-1)


import sys
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, sys.stdin.readline().split())
	if k - 1 - n * b < 0:
		print(-1)
		continue
	print(min(n, (k - 1 - n * b) // (a - b)))


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split(' '))
	c = k - n * a
	if c > 0:
		print(n)
	else:
		turn = (-c + 1) / (a - b)
		if turn > int(turn):
			turn += 1
			turn = int(turn)
		else:
			turn = int(turn)
		if n - turn >= 0:
			print(n - turn)
		else:
			print(-1)


import math
from sys import stdin, stdout
mod = 1000000007
t = int(stdin.readline())
while t > 0:
	(k, n, a, b) = list(map(int, stdin.readline().split()))
	(low, high) = (0, n)
	(mid, ans) = (0, -1)
	while low <= high:
		mid = low + int((high - low) / 2)
		if mid < (k - b * n) / (a - b):
			ans = mid
			low = mid + 1
		else:
			high = mid - 1
	stdout.write(f'{ans}\n')
	t -= 1


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	if k <= n * b:
		print(-1)
		continue
	else:
		print(min(n, math.ceil((k - n * b) / (a - b) - 1)))


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
from collections import defaultdict, deque
import heapq
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split(' '))
	if n * b >= k:
		print(-1)
		continue
	extra = k - n * b
	z = extra // (a - b)
	ans = min(n, z)
	if ans * a + (n - ans) * b == k:
		ans -= 1
	print(ans)


q = int(input())
for qi in range(q):
	(k, n, a, b) = map(int, input().split())
	dif = n * a
	if dif < k:
		print(n)
	else:
		exc = dif - k + 1
		inc = a - b
		nb = (exc + inc - 1) // inc
		if nb > n:
			print(-1)
		else:
			print(n - nb)


import math
cases = int(input())
for i in range(0, cases):
	ln = [int(i) for i in input().split(' ')]
	k = ln[0]
	t = ln[1]
	a = ln[2]
	b = ln[3]
	if k / t <= b:
		print(-1)
	else:
		num = b * t
		turns = (k - num) / (a - b)
		if turns % 1 == 0:
			print(min(t, int(turns) - 1))
		else:
			print(min(t, math.floor(turns)))


q = int(input())
res = []
for i in range(q):
	(k, n, a, b) = [int(x) for x in input().split()]
	if k // b < n:
		res.append(-1)
	else:
		l = 0
		r = n
		while l <= r:
			m = (l + r) // 2
			if m * a + (n - m) * b < k:
				l = m + 1
			else:
				r = m - 1
		res.append((l + r) // 2)
for i in res:
	print(i)


def process_test_case():
	(k, n, a, b) = list(map(int, input().split()))
	if n * b >= k:
		return -1
	t1 = k - n * b
	t2 = a - b
	result = min(n, t1 // t2 - (1 if t1 % t2 == 0 else 0))
	return result
test_cases = int(input())
for i in range(test_cases):
	print(process_test_case())


n = int(input())
for i in range(n):
	(k, n, a, b) = [int(x) for x in input().split()]
	k -= 1
	if b * n > k:
		print(-1)
	elif (k - b * n) // (a - b) > n:
		print(n)
	else:
		print((k - b * n) // (a - b))


def bin_s():
	(a, b, c, d) = map(int, input().split())
	(lo, hi, ans) = (0, min(b, a // c), -1)
	while lo <= hi:
		mid = (lo + hi) // 2
		z = (a - mid * c) // d
		if mid + z > b:
			ans = mid
			lo = mid + 1
		elif mid + z == b and a - z * d - c * mid > 0:
			ans = mid
			lo = mid + 1
		else:
			hi = mid - 1
	print(ans)
for _ in ' ' * int(input()):
	bin_s()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(power, n, a, b) = num_input()
	if a == b:
		x = power - a * n
		if x >= 1:
			print(n)
		else:
			print(-1)
		return
	x = (b * n - power + 1) // (b - a)
	if x > n:
		print(n)
	elif x < 0:
		print(-1)
	else:
		print(x)
t = 1
t = int(input())
for _ in range(t):
	solve()


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
	else:
		r = n
		l = 0
		mid = -1
		mid1 = -2
		while mid != mid1:
			mid1 = mid
			mid = (l + r) // 2
			if mid * a + (n - mid) * b < k:
				l = mid
			else:
				r = mid
		if r * a + (n - r) * b < k:
			print(max(r, mid))
		else:
			print(mid)


import math
import sys

def rl():
	return sys.stdin.readline().strip()

def rn():
	return list(map(int, sys.stdin.readline().strip().split()))

def rnn():
	return map(int, sys.stdin.readline().strip().split())

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l
q = int(input())
for _ in range(q):
	(k, n, a, b) = rnn()
	k -= n * a
	if k > 0:
		print(n)
	else:
		k = -k + 1
		diff = a - b
		turns = (k + diff - 1) // diff
		if turns > n:
			print(-1)
		else:
			print(n - turns)


def Check(x):
	if x * a >= k:
		return False
	xx = k - x * a
	yy = n - x
	if yy * b >= xx:
		return False
	return True
T = int(input())
while T > 0:
	(k, n, a, b) = map(int, input().split())
	l = 0
	r = n
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if Check(mid):
			l = mid + 1
			ans = mid
		else:
			r = mid - 1
	print(ans)
	T -= 1


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
q = ii()
for _ in range(q):
	(k, n, a, b) = f()
	if b * n >= k:
		print(-1)
	else:
		print(min(n, (k - n * b - 1) // (a - b)))


import math
q = int(input())
for _ in range(q):
	(k, n, a, b) = input().split(' ')
	k = int(k)
	n = int(n)
	a = int(a)
	b = int(b)
	jp = 0
	if k / a > n:
		jp += n
		k -= a * n
		n = 0
	else:
		j = int((k / a - n) / (b / a - 1)) - 1
		while (k - j * b) / a <= n - j and n - j > 0 and (k - j * b > 0):
			j += 1
		k -= j * b
		n -= j
		if n > 0 and k / a > n:
			jp += n
			k -= a * n
			n = 0
	if n == 0 and k > 0:
		print(jp)
	else:
		print(-1)


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, str(input()).split(' '))
	if k - n * b > 0:
		k = k - 1
		res = (k - n * b) / float(a - b)
		res = int(math.floor(res))
		if res > n:
			res = n
		print(res)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	(k, n, a, b) = map(int, input().split())
	print(max(min((k - n * b + (a - b - 1)) // (a - b) - 1, n), -1))


from sys import stdin, stdout
global k, n, a, b

def bs(left, right):
	res = -1
	while left <= right:
		middle = (left + right) // 2
		_n = n
		_k = k
		_n -= middle
		_k -= middle * a
		y = (_k - 1) // b
		if y >= _n:
			res = middle
			left = middle + 1
		else:
			right = middle - 1
	return res
q = int(stdin.readline())
while q > 0:
	q -= 1
	(k, n, a, b) = [int(x) for x in stdin.readline().split()]
	stdout.write(str(bs(0, min((k - 1) // a, n))) + '\n')


q = int(input())
for _ in range(q):
	knab = input().split()
	k = int(knab[0])
	n = int(knab[1])
	a = int(knab[2])
	b = int(knab[3])
	if k <= n * b:
		print(-1)
	else:
		print(min((k - 1 - n * b) // (a - b), n))


import math
q = int(input())
for Q in range(q):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
	elif a * n < k:
		print(n)
	else:
		print(n - math.ceil((a * n - k + 1) / (a - b)))


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = [int(x) for x in input().split()]
	if b * n >= k:
		print(-1)
	elif a * n < k:
		print(n)
	else:
		x = (k - b * n) / (a - b)
		print(math.ceil(x) - 1)


import math
q = int(input())
for i in range(q):
	(n, k, a, b) = map(int, input().split())
	if n - k * b > 0 and n - (k - 1) * b > b:
		if k < (n - b) / a:
			print(k)
		else:
			if (n - b * k) % (a - b) == 0:
				answ = (n - b * k) // (a - b) - 1
			else:
				answ = math.floor((n - b * k) / (a - b))
			print(min(k, answ))
	else:
		print(-1)


q = int(input())
for i in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	if n * b >= k:
		print(-1)
		continue
	l = 0
	r = min(k // a + 1, n + 1)
	while r - l > 1:
		m = (r + l) // 2
		if (k - a * m - 1) // b >= n - m and k - a * m > 0:
			l = m
		else:
			r = m
	print(l)


test = int(input())
for i in range(test):
	ls = list(map(int, input().split()))
	if ls[0] <= ls[3] * ls[1]:
		print(str(-1))
	else:
		m = (ls[0] - ls[1] * ls[3]) // (ls[2] - ls[3])
		n = (ls[0] - ls[1] * ls[3]) / (ls[2] - ls[3])
		if m == n:
			if m > ls[1]:
				k = ls[1]
			else:
				k = m - 1
		elif m > ls[1]:
			k = ls[1]
		else:
			k = m
		print(str(k))


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	k1 = k
	v = k
	x = k // a
	first = 0
	if k - (x - 1) * a <= a:
		x -= 1
	k = k - x * a
	first = x
	y = k // b
	if k - (y - 1) * b <= b:
		y -= 1
	second = y
	if first + second >= n:
		print(min(first, n))
	else:
		l = 0
		h = first
		f = 0
		flag = 0
		while h >= l:
			k1 = v
			mid = (l + h) // 2
			k1 = k1 - mid * a
			y = k1 // b
			if k1 - (y - 1) * b <= b:
				y -= 1
			if mid + y >= n:
				f = mid
				l = mid + 1
				flag = 1
			else:
				h = mid - 1
		if flag == 1:
			print(f)
		else:
			print(-1)


for _ in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	ans = k - n * a
	k = ans
	if k > 0:
		print(n)
		continue
	k = -k
	k += 1
	d = a - b
	t = (k + d - 1) // d
	if t > n:
		print('-1')
		continue
	print(n - t)


def check(charge, n, a, b):
	prev = -1
	(l, r) = (0, n)
	while l <= r:
		mid = (l + r) // 2
		if mid * a + (n - mid) * b < charge:
			prev = mid
			l = mid + 1
		else:
			r = mid - 1
	return prev
n = int(input())
for i in range(n):
	l = list(map(int, input().strip().split()))
	print(check(l[0], l[1], l[2], l[3]))


import sys

def eprint(*args, **kwargs):
	if __debug__:
		print(*args, file=sys.stderr, **kwargs)
for _ in range(int(input())):
	turns = 0
	(k, n, a, b) = map(int, input().split(' '))
	x = (k - b * n - 1) // (a - b)
	if x < 0:
		x = -1
	x = min(x, n)
	print(x)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	j = n * b
	if j >= k:
		print(-1)
		continue
	i = (k - j) // (a - b)
	if i * (a - b) + j >= k:
		print(min(i - 1, n))
	else:
		print(min(i, n))


import sys
input = sys.stdin.readline
m = int(input())
for ii in range(m):
	(k, n, a, b) = [int(i) for i in input().split()]
	if k <= n * b:
		print(-1)
	else:
		delta = a - b
		new = k - b * n
		print(min((new - 1) // delta, n))


from math import ceil
q = int(input())
for _ in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	if b * n >= k:
		print(-1)
	else:
		d = a * n - k + 1
		if d <= 0:
			print(n)
		else:
			r = a - b
			print(n - ceil(d / r))


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
hg = lambda x, y: (y + x - 1) // x * x
for _ in range(I()):
	(k, n, a, b) = R()
	l = 0
	r = n
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if m * a + (n - m) * b < k:
			ans = m
			l = m + 1
		else:
			r = m - 1
	print(ans)


for i in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	l = 0
	h = n
	ans = -1
	while l <= h:
		mid = (l + h) // 2
		if a * mid + (n - mid) * b < k:
			ans = mid
			l = mid + 1
		else:
			h = mid - 1
	print(ans)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	i = -1
	n2 = 1
	while n2 <= n:
		n2 *= 2
	while n2:
		j = i + n2
		if j <= n and j * a + (n - j) * b < k:
			i = j
		n2 //= 2
	print(i)


q = int(input())
itog = []
for i in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	if k <= n * b:
		itog.append(-1)
	elif k > n * a:
		itog.append(n)
	else:
		left = 0
		right = n
		while left + 1 != right:
			mid = (left + right) // 2
			if k - a * mid - b * (n - mid) <= 0:
				right = mid
			else:
				left = mid
		itog.append(left)
for i in itog:
	print(i)


from sys import stdin, stdout

def b_s(l, r, a, b, n, k):
	while l + 1 < r:
		m = (l + r) // 2
		if valid(m, a, b, n, k):
			l = m
		else:
			r = m
	return l

def valid(num, a, b, n, k):
	rounds = 0
	if k - num * a > 0:
		rounds += num
		k -= num * a
	else:
		return False
	rounds += k // b - 1 if k % b == 0 else k // b
	return rounds >= n
outputs = []
t = int(stdin.readline().strip())
for __ in range(t):
	(k, n, a, b) = map(int, stdin.readline().strip().split())
	l = b_s(0, n + 1, a, b, n, k)
	if valid(l, a, b, n, k):
		outputs.append(l)
	else:
		outputs.append(-1)
for output in outputs:
	stdout.write(f'{output}\n')


t = int(input())
for i in range(t):
	(k, n, a, b) = list(map(int, input().split()))
	if n * b >= k:
		print(-1)
		continue
	uk1 = -1
	uk2 = n + 1
	while uk2 - uk1 > 1:
		mid = (uk2 + uk1) // 2
		if mid * a + (n - mid) * b < k:
			uk1 = mid
		else:
			uk2 = mid
	print(uk1)


import math
q = int(input())
while q > 0:
	(k, n, a, b) = [int(x) for x in input().split()]
	c = k - n * a
	if c > 0:
		print(n)
	else:
		diff = a - b
		turn = math.ceil((-c + 1) / diff)
		if turn > n:
			print(-1)
		else:
			print(n - turn)
	q -= 1


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k > n * a:
		print(n)
		continue
	else:
		charge_needed = k - n * a
		diff = a - b
		turn = -charge_needed // diff + 1
		if n - turn >= 0:
			print(n - turn)
		else:
			print(-1)


for _ in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	if k <= b * n:
		print(-1)
		continue
	L = 0
	R = n + 1
	while R - L > 1:
		mid = (R + L) // 2
		if mid * a + (n - mid) * b < k:
			L = mid
		else:
			R = mid
	print(L)


import math
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	x = (k - b * n) / (a - b)
	x1 = (k - b * n) // (a - b)
	if x <= 0:
		if k - n * b > 0:
			print('0')
		else:
			print('-1')
	elif x1 == x:
		print(min(x1 - 1, n))
	else:
		print(min(x1, n))


t = int(input())
for tt in range(t):
	(k, n, a, b) = map(int, input().split())
	t1 = (k - 1) // b
	if t1 >= n:
		l = 0
		ans = 0
		r = t1 + 5
		while l <= r:
			mid = l + (r - l) // 2
			tmp = 0
			if k - mid * a > 0:
				tmp += mid
				rem = k - mid * a
				tmp += max(0, (rem - 1) // b)
				if tmp >= n:
					ans = max(ans, mid)
					l = mid + 1
					continue
				else:
					r = mid - 1
					continue
			else:
				r = mid - 1
		print(min(ans, n))
	else:
		print('-1')


import sys
input = sys.stdin.readline
Q = int(input())
for testcase in range(Q):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
		continue
	print(min(n, (k - n * b - 1) // (a - b)))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(k, n, a, b) = M()
	just = (k - 1) // a
	if just >= n:
		print(n)
	else:
		y = mt.ceil((a * n - k + 1) / (a - b))
		x = n - y
		if k - (x * a + y * b) <= 0:
			print(-1)
		elif x < 0:
			print(-1)
		else:
			print(x)


q = int(input())
for query in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	if n * b > k:
		print(-1)
	else:
		print(min(n, (k - n * b - 1) // (a - b)))


req = int(input())
for i in range(req):
	(battery, amount, a, b) = map(int, input().split())
	battery -= 1
	maximum = battery // b
	if maximum < amount:
		print(-1)
	else:
		c = a - b
		battery -= b * amount
		print(min(battery // c, amount))


def readInts():
	return [int(x) for x in input().split()]
Q = int(input())
for q in range(Q):
	[k, n, a, b] = readInts()
	k -= n * b
	if k <= 0:
		print(-1)
		continue
	spendable = k - 1
	justPlay = min(n, spendable // (a - b))
	print(justPlay)


def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problem1():
	a = inp(int)
	n = -1
	while n < 0:
		s = 0
		tmp = a
		while tmp:
			s += tmp % 10
			tmp = tmp // 10
		if s % 4 == 0:
			n = a
		a += 1
	print(n)

def problem2():
	q = inp(int)
	for _ in range(q):
		(n, k) = inp(int)
		a = inp(int, strip=False)
		(mn, mx) = (0, 10 ** 10)
		for price in a:
			mx = min(price + k, mx)
			mn = max(price - k, mn)
		if mn <= mx:
			print(mx)
		else:
			print(-1)

def problem3():
	q = inp(int)
	for _ in range(q):
		(k, n, a, b) = inp(int)
		if b * n >= k:
			print(-1)
		elif a * n < k:
			print(n)
		else:
			print((k - b * n - 1) // (a - b))

def problem4():
	pass

def problem5():
	pass
problem3()


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(k, n, a, b) = In()
		if k <= n * b:
			print(-1)
		else:
			t = math.ceil((k - n * b) / (a - b))
			if t - 1 >= n:
				print(n)
			else:
				print(t - 1)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


from sys import *
from math import *
q = int(stdin.readline())
for _ in range(q):
	(k, n, a, b) = map(int, stdin.readline().split())
	l = 0
	h = n - 1
	if a * n < k:
		print(n)
	else:
		ans = -1
		while l <= h:
			p = (l + h) // 2
			x = a * p
			y = k - x
			m = y // b
			if y % b == 0:
				m -= 1
			if m + p >= n:
				l = p + 1
				ans = p
			elif m + p < n:
				h = p - 1
		print(ans)


t = int(input())
for tc in range(t):
	(k, n, a, b) = map(int, input().split())
	if k // b == n and k % b == 0 or k // b < n:
		print(-1)
		continue

	def binsearch(k, b, a, n):
		left = 0
		right = n
		ans = 0
		while left <= right:
			mid = (left + right) // 2
			leftover = k - (a * mid + b * (n - mid))
			if leftover > 0:
				left = mid + 1
			elif leftover <= 0:
				right = mid - 1
		return left - 1
	print(binsearch(k, b, a, n))


for t in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	m = (k - b * n - 1) // (a - b)
	if m < 0:
		print(-1)
	elif m > n:
		print(n)
	else:
		print(m)


q = int(input())
while q > 0:
	(k, n, a, b) = input().split()
	k = int(k)
	n = int(n)
	a = int(a)
	b = int(b)
	if n * b >= k:
		print('-1')
	else:
		i = a - b
		r = (k - n * b - 1) // i
		if r > n:
			r = n
		print(r)
	q -= 1


N = int(input())
for i in range(N):
	(k, n, a, b) = (int(j) for j in input().split())
	D = k - n * b
	if D <= 0:
		print(-1)
		continue
	print(min(n, (D - 1) // (a - b)))


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print('-1')
	else:
		x = (k - n * b) // (a - b)
		x = min(x, n)
		while True:
			y = n - x
			amt = a * x + b * y
			if amt < k and x + y == n:
				print(x)
				break
			x -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(k, n, a, b) = LI()
		if n * b >= k:
			rr.append(-1)
		else:
			k -= n * b + 1
			c = a - b
			rr.append(min(n, k // c))
	return JA(rr, '\n')
print(main())


Q = int(input())

def solve():
	(k, n, a, b) = map(int, input().split())
	if k - n * b <= 0:
		print(-1)
		return
	ok = 0
	ng = n + 1
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if k - (mid * a + (n - mid) * b) > 0:
			ok = mid
		else:
			ng = mid
	print(ok)
for _ in range(Q):
	solve()


from math import ceil
for ad in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	x = ceil((k - n * b) / (a - b))
	x -= 1
	if k > n * b:
		print(min(x, n))
	else:
		print(-1)


from sys import stdin
from math import *

def main():
	q = int(stdin.readline())
	for query in range(q):
		(k, n, a, b) = [int(x) for x in stdin.readline().strip().split()]
		k -= n * a
		if k > 0:
			print(n)
		else:
			k = -k
			k += 1
			diff = a - b
			turns = (k + diff - 1) // diff
			if turns > n:
				print(-1)
			else:
				print(n - turns)
main()


def binary(l, r):
	x = (l + r) // 2
	if l >= r or r - l == 1:
		return int(x)
	if k > a * x + b * (n - x):
		return binary(x, r)
	else:
		return binary(l, x - 1)
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print(-1)
	else:
		x = binary(0, n)
		p = x + 1
		if k > a * p + b * (n - p):
			print(p)
		else:
			print(x)


def solve(k, n, a, b):
	if n * b >= k:
		return -1
	else:
		c = k - n * b - 1
		ta = c // (a - b)
		return min(n, ta)
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	print(solve(k, n, a, b))


q = int(input())
for l in range(q):
	(k, n, a, b) = map(int, input().split())
	ans = -1
	if n * b >= k:
		ans = -1
	else:
		hi = n + 1
		lo = -1
		while hi - lo > 1:
			mid = (hi + lo) // 2
			if mid * a + (n - mid) * b < k:
				lo = mid
			else:
				hi = mid
		ans = lo
	print(ans)


I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(k, n, a, b) = I()
	if k <= n * b:
		print(-1)
		continue
	print(min(n, (k - n * b - 1) // (a - b)))


from sys import stdin, setrecursionlimit
from itertools import combinations
import collections

def check(num):
	if num * a + (n - num) * b < k:
		return True
	return False
q = int(stdin.readline().strip())
for _ in range(q):
	(k, n, a, b) = list(map(int, stdin.readline().split()))
	start = 0
	end = n
	while True:
		if start >= end:
			if check(start - 1):
				start -= 1
			break
		mid = (start + end) // 2
		if check(mid):
			start = mid + 1
		else:
			end = mid - 1
	if check(start + 1):
		print(start + 1)
	elif check(start):
		print(start)
	else:
		print(-1)


import math
import sys

def solve(k, n, a, b):
	if k <= n * b:
		return -1
	elif k > n * a:
		return n
	elif (k - n * b) % (a - b) == 0:
		return (k - n * b) // (a - b) - 1
	else:
		return math.floor((k - n * b) / (a - b))
ls = []
for line in sys.stdin:
	ls.append(line.split())
i = 1
while i < len(ls):
	q = list(map(int, ls[i]))
	(k, n, a, b) = (q[0], q[1], q[2], q[3])
	print(solve(k, n, a, b))
	i += 1


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(k, n, a, b) = cin()
	if (k - b - 1) // b < n - 1:
		print(-1)
	else:
		ans = max(min((k - a - 1) // a + 1, (k - n * b - 1) // (a - b), n), 0)
		print(ans)


from sys import stdin, stdout
T = int(stdin.readline())
for i in range(T):
	(k, n, a, b) = map(int, stdin.readline().split())
	ans = -1
	l = 0
	r = n
	while l <= r:
		mid = (l + r) // 2
		if a * mid + b * (n - mid) < k:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	print(ans)


import math
q = int(input())
for Q in range(q):
	knab = input().split()
	k = int(knab[0])
	n = int(knab[1])
	a = int(knab[2])
	b = int(knab[3])
	low = 0
	high = n
	if n * b < k:
		while low < high:
			t = (low + high + 1) // 2
			if t * a + (n - t) * b < k:
				low = t
			else:
				high = t - 1
		print(low)
	else:
		print(-1)


from math import ceil, floor
q = int(input())
for i in range(q):
	(k, n, a, b) = [int(i) for i in input().split()]
	x = (n * a - k) // (a - b)
	if x + 1 < 0:
		print(n)
		continue
	otv = n - x - 1
	if otv < 0:
		print(-1)
	else:
		print(otv)


import math
for i in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	x = math.ceil(k / b)
	x -= 1
	if x < n:
		print(-1)
	else:
		z = k - b * n - 1
		print(min(n, z // (a - b)))


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	x = k - n * a
	if x > 0:
		print(n)
	else:
		diff = a - b
		c = math.ceil((n * a - k + 1) / diff)
		res = n - c
		if res < -1:
			res = -1
		print(res)


s = input().split()
T = int(s[0])
for i in range(1, T + 1):
	s1 = input().split()
	k = int(s1[0])
	n = int(s1[1])
	a = int(s1[2])
	b = int(s1[3])
	k -= b * n
	if k <= 0:
		print(-1)
	else:
		print(int(min((k - 1) / (a - b), n)))


import sys
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	(k, n, a, b) = map(int, input().split())
	p = int(ceil((k - n * b) / (a - b))) - 1
	if p < 0:
		print(-1)
	else:
		print(min(n, p))


def bin_sarch(l, r, a, b, n, k):
	if l > r:
		return r
	mid = (l + r) // 2
	inter_result = a * mid + b * (n - mid)
	if inter_result < k:
		return bin_sarch(mid + 1, r, a, b, n, k)
	else:
		return bin_sarch(l, mid - 1, a, b, n, k)
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	res = bin_sarch(0, n, a, b, n, k)
	if res < 0:
		print('-1')
	else:
		print(res)


import math
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	out = math.floor((k - n * b - 1) / (a - b))
	if out < 0:
		print(-1)
	else:
		print(min(n, out))


t = int(input())
for i in range(t):
	(k, n, a, b) = map(int, input().split())
	L = 0
	H = n
	ans = -1
	while L <= H:
		mid = (L + H) // 2
		if mid * a + (n - mid) * b < k:
			ans = mid
			L = mid + 1
		else:
			H = mid - 1
	print(ans)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print('-1')
	elif n * a < k:
		print(n)
	else:
		p = n * a
		t = (p - k) // (a - b)
		if (n - t) * a + t * b < k:
			print(n - t)
		else:
			print(n - t - 1)


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	c = k - a * n
	if c > 0:
		print(n)
	else:
		diff = a - b
		turns = -c // diff + 1
		if n - turns >= 0:
			print(n - turns)
		else:
			print(-1)


q = int(input())
for i in range(q):
	(n, k, a, b) = map(int, input().split())
	x = a * k
	raz = a - b
	if x < n:
		print(k)
	elif b * k >= n:
		print(-1)
	else:
		d = (x - n) // raz + 1
		print(k - d)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print(-1)
	elif k > a * n:
		print(n)
	elif k == a * n:
		print(n - 1)
	else:
		x = (k - 1 - b * n) // (a - b)
		y = x + 1
		if k > y * a + (n - y) * b and n - y >= 0:
			x += 1
		print(min(n, x))


from sys import stdin
n = int(stdin.readline().strip())
for i in range(n):
	(k, t, a, b) = map(int, stdin.readline().strip().split())
	low = 0
	high = t
	while high - low > 1:
		mid = (high + low) // 2
		x = (t - mid) * b + mid * a
		if x < k:
			low = mid
		else:
			high = mid
	x1 = (t - high) * b + high * a
	x2 = (t - low) * b + low * a
	if x1 < k:
		print(high)
	elif x2 < k:
		print(low)
	else:
		print(-1)


def calc(x, n, a, b):
	return a * x + b * (n - x)

def bn(k, low, high, n, a, b):
	if high - low < 3:
		for i in range(high, low - 1, -1):
			if calc(i, n, a, b) < k:
				return i
		return -1
	mid = (low + high) // 2
	if calc(mid, n, a, b) < k:
		return bn(k, mid, high, n, a, b)
	else:
		return bn(k, low, mid - 1, n, a, b)
Q = int(input())
for q in range(Q):
	(k, n, a, b) = [int(x) for x in input().split()]
	print(bn(k, 0, n, n, a, b))


for i in range(int(input())):
	(k, n, a, b) = [int(x) for x in input().split()]
	t = k // b
	if k - (t - 1) * b <= b:
		t -= 1
	if t < n:
		print(-1)
		continue
	l = 0
	r = n + 1
	while r - l > 1:
		m = (r + l) // 2
		if k - (m - 1) * a <= a:
			r = m
		elif k - m * a - (n - m - 1) * b <= b:
			r = m
		else:
			l = m
	print(l)


for q in range(int(input())):
	(k, n, a, b) = [int(s) for s in input().split()]
	if n * b + 1 > k:
		print(-1)
	else:
		print(min((k - 1 - n * b) // (a - b), n))


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	l = k - b * n
	z = a - b
	if l > 0:
		if l % z == 0:
			if l // z - 1 <= n:
				print(l // z - 1)
			else:
				print(n)
		elif l // z <= n:
			print(l // z)
		else:
			print(n)
	else:
		print(-1)


def binarySearch(k, n, a, b):
	l = 0
	r = n
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		res = mid * a + (n - mid) * b
		if res < k:
			l = mid + 1
			ans = mid
		elif res >= k:
			r = mid - 1
	return ans
time = int(input().strip())
for i in range(time):
	arr = input().strip().split()
	arr = [int(j) for j in arr]
	result = binarySearch(arr[0], arr[1], arr[2], arr[3])
	print(result)


num_quests = int(input())
for i in range(num_quests):
	(k, n, a, b) = map(int, input().split())
	rest = k - b * n
	if rest <= 0:
		print(-1)
		continue
	dif = a - b
	num_a = -100
	if rest % dif == 0:
		num_a = max(0, rest // dif - 1)
	else:
		num_a = rest // dif
	num_a = min(num_a, n)
	print(int(num_a))


from sys import stdin

def func(k, n, a, b):
	if k <= b * n:
		return -1
	(l, r) = (0, n)
	while l <= r:
		m = (l + r) // 2
		x = m * a + (n - m) * b
		if x < k:
			l = m + 1
		else:
			r = m - 1
	return r
q = int(input())
lines = stdin.readlines()
for line in lines:
	(k, n, a, b) = map(int, line.split())
	print(func(k, n, a, b))


def go():
	(k, n, a, b) = [int(i) for i in input().split(' ')]
	value = -1
	if k / a > n:
		return n
	if k / b <= n:
		return -1
	low = 1
	high = n - 1
	while low < high:
		mid = (low + high) // 2
		value = mid * a + (n - mid) * b
		if value < k:
			low = mid + 1
		else:
			high = mid
	if low * a + (n - low) * b >= k:
		return low - 1
	return low
Q = int(input())
for q in range(Q):
	print(go())


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 99999999999999999999999999999999

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		(k, n, a, b) = ria()
		y = (a * n - k) // (a - b) + 1
		ans = max(-1, min(n, n - y))
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for _ in range(int(input())):
	(s, n, a, b) = map(int, input().split())
	if b * n >= s:
		print(-1)
	elif a * n < s:
		print(n)
	else:
		x = (s - b * n) // (a - b)
		r = (s - b * n) % (a - b)
		if r == 0:
			x -= 1
		print(x)


def main():
	for _ in range(int(input())):
		(k, n, a, b) = map(int, input().split())
		if n * b >= k:
			print('-1')
		else:
			print(min(n, (k - 1 - b * n) // (a - b)))
main()


def main():
	for q in range(0, int(input())):
		solve()

def solve():
	(k, n, a, b) = map(int, input().split())
	x = bs(0, n, lambda x: k - b * x - a * (n - x) > 0)
	if x > n:
		x = -1
	else:
		x = n - x
	print(x)

def bs(low, high, test):
	while low <= high:
		mid = (low + high) // 2
		if test(mid):
			high = mid - 1
		else:
			low = mid + 1
	return low
main()


import sys
from collections import Counter
import itertools

def input():
	return sys.stdin.readline().strip()

def dinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def f(a):
	t = 1
	for i in range(a):
		t *= i + 1
	return t

def cor(n, k):
	return int(f(n) / (f(k) * f(n - k)))

def main():
	(k, n, a, b) = rinput()
	t = b * n
	if t >= k:
		print(-1)
	else:
		a -= b
		k -= t + 1
		print(min(k // a, n))
for i in range(int(input())):
	main()


import math
n = int(input())
while n > 0:
	n = n - 1
	a = [int(i) for i in input().split()]
	if a[0] / a[3] > a[1]:
		out = math.ceil((a[0] - a[1] * a[3]) / (a[2] - a[3])) - 1
		print(out if out < a[1] else a[1])
	else:
		print(-1)


import math
q = int(input())
for query in range(q):
	(k, n, a, b) = map(int, input().split())
	if k / n <= b:
		print(-1)
	else:
		a_max = (k - b * n) / (a - b)
		if a_max > n:
			print(n)
		else:
			print(math.ceil(a_max - 1))


t = int(input())
for i in range(t):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		print(-1)
	else:
		ans = (k - b * n) / (a - b)
		if ans > n:
			ans = n
		elif int(ans) == ans:
			ans -= 1
		ans = int(ans)
		print(ans)


for _ in range(int(input())):
	(k, n, a, b) = list((int(x) for x in input().split()))
	d = a - b
	k -= n * b
	if k <= 0:
		print(-1)
	else:
		print(min(n, (k - 1) // d))


def valid(plays, k, n, a, b):
	newK = k - plays * a
	if newK <= 0:
		return False
	extra = n - plays
	if extra * b >= newK:
		return False
	return True
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print(-1)
	else:
		(l, r) = (0, n)
		result = 0
		while l <= r:
			mid = (l + r) // 2
			if valid(mid, k, n, a, b):
				result = mid
				l = mid + 1
			else:
				r = mid - 1
		print(result)


def is_possible(x, total, n, a, b):
	if total - x * a - (n - x) * b > 0:
		return True
	else:
		return False
T = int(input())
for _ in range(T):
	(total, n, a, b) = list(map(int, input().split()))
	low = 0
	high = n
	mid = (high + low) // 2
	while low < mid:
		if is_possible(mid, total, n, a, b):
			low = mid
			mid = (high + low) // 2
		else:
			high = mid
			mid = (high + low) // 2
	if is_possible(high, total, n, a, b):
		print(high)
	elif is_possible(mid, total, n, a, b):
		print(mid)
	else:
		print('-1')


import math
q = int(input())
for t in range(q):
	(k, n, a, b) = [int(x) for x in input().split()]
	x = (k - n * b) / (a - b)
	if x <= 0:
		print(-1)
	else:
		f = math.floor(x)
		ans = f
		if f == x:
			ans = x - 1
		if ans <= n:
			print(int(ans))
			continue
		elif n * a < k:
			print(n)
		else:
			print(n - 1)


import sys
q = int(input())
lines = sys.stdin.readlines()
res = []
for i in range(q):
	(k, n, a, b) = [int(i) for i in lines[i].split()]
	k -= 1
	if k < n * b:
		res.append('-1')
		continue
	diff = a - b
	num = (k - n * b) // diff
	if num > n:
		num = n
	res.append(str(num))
print('\n'.join(res))


q = int(input())
for w in range(q):
	iarr = list(map(int, input().split()))
	k = iarr[0]
	n = iarr[1]
	a = iarr[2]
	b = iarr[3]
	if k <= b * n:
		print(-1)
	else:
		yo = (k - b * n) // (a - b)
		if yo * (a - b) == k - b * n:
			yo -= 1
		print(min(yo, n))


T = int(input())
for i in range(T):
	(k, n, a, b) = [int(i) for i in input().split(' ')]
	moves = (k - b * n - 1) // (a - b)
	if moves < 0:
		print(-1)
		continue
	if moves > n:
		print(n)
	else:
		print(moves)


def plottt(mre, nre, cre, are, bre):
	xcxfd = cre - (mre * are + (nre - mre) * bre)
	if xcxfd > 0:
		return 1
	else:
		return 0
qre = int(input())
for _ in range(qre):
	(cre, nre, are, bre) = [int(i) for i in input().strip().split(' ')]
	if cre > nre * bre:
		lre = 0
		rre = nre
		while lre <= rre:
			mid = (lre + rre) // 2
			if plottt(mid, nre, cre, are, bre):
				lre = mid
			else:
				rre = mid
			if lre == rre:
				print(lre)
				break
			if lre == rre - 1:
				if plottt(rre, nre, cre, are, bre):
					print(rre)
				else:
					print(lre)
				break
	else:
		print(-1)


n = int(input())
for i1 in range(n):
	(m, k, a, b) = map(int, input().split())
	m -= 1
	if k * min(a, b) > m:
		print(-1)
	elif a < b:
		print(m // a)
	else:
		x = (m - k * b) // (a - b)
		if x > k:
			print(k)
		else:
			print((m - k * b) // (a - b))


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	k1 = k - n * b
	if k1 > 0:
		bache = k - b * n
		diff = a - b
		lol = bache // diff
		if k - lol * a - (n - lol) * b > 0:
			print(min(n, lol))
		else:
			lol -= 1
			print(min(n, lol))
	else:
		print('-1')


import sys
input = sys.stdin.readline

def judge(x):
	if not k - (x - 1) * a > a:
		return False
	if not k - x * a - (n - x - 1) * b > b:
		return False
	return True

def binary_search():
	(l, r) = (0, n)
	while l <= r:
		mid = (l + r) // 2
		if judge(mid):
			l = mid + 1
		else:
			r = mid - 1
	return r
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	print(binary_search())


import math
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print('-1')
	elif k > a * n:
		print(n)
	else:
		x = (k - b * n) / (a - b)
		x = math.floor(x)
		while k - a * x - b * (n - x) <= 0:
			x -= 1
		print(x)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
		continue
	l = 0
	r = n + 1
	while r - l > 1:
		m = (r + l) // 2
		if m * a + (n - m) * b < k:
			l = m
		else:
			r = m
	print(l)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
	else:
		num = k - b * n - 1
		deno = a - b
		print(min(num // deno, n))


def predicate(index, a, b, k, n):
	if index * a + b * (n - index) < k:
		return True
	else:
		return False

def bs(start, end, a, b, k, n):
	l = start
	h = end
	while l < h:
		mid = l + (h - l) // 2
		if predicate(mid, a, b, k, n) == True:
			l = mid + 1
		else:
			h = mid
	if predicate(end, a, b, k, n) == True:
		return end
	return l - 1
n = int(input())
for i in range(n):
	(k, n, a, b) = map(int, input().split())
	if k - n * b <= 0:
		print(-1)
	else:
		ans = min(n, (k - n * b - 1) // (a - b))
		print(ans)


import sys
(k, n, a, b) = (None, None, None, None)

def check(x):
	return x * a + (n - x) * b < k
for i in range(int(input())):
	(k, n, a, b) = [*map(int, input().split())]
	(lo, hi) = (0, n)
	while lo < hi:
		mid = (lo + hi + 1) // 2
		if check(mid):
			lo = mid
		else:
			hi = mid - 1
	if check(lo):
		print(lo)
	else:
		print(-1)


T = int(input())
for case in range(T):
	(n, k, a, b) = list(map(int, input().split()))
	n = n - 1
	r = n - k * b
	if r < 0:
		print(-1)
		continue
	print(min(r // (a - b), k))


import sys
input = sys.stdin.readline
from math import floor, ceil

def calc(k, n, a, b, num_a):
	n -= num_a
	k -= num_a * a
	num_b = floor((k - 1) / b)
	n -= num_b
	k -= num_b * b
	return n <= 0 and k > 0

def bin_search(k, n, a, b):
	low = 0
	high = k // a + 1
	best = 0
	while low <= high:
		num_a = (low + high) // 2
		res = calc(k, n, a, b, num_a)
		if res:
			low = num_a + 1
			best = max(best, num_a)
		else:
			high = num_a - 1
	return best

def solve(k, n, a, b):
	num_turns_a = floor((k - 1) / a)
	num_turns_b = floor((k - 1) / b)
	if num_turns_a >= n:
		return n
	elif num_turns_b < n:
		return -1
	else:
		return bin_search(k, n, a, b)
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	print(solve(k, n, a, b))


import sys
input = sys.stdin.readline

def main():
	q = int(input())
	for _ in range(q):
		(k, n, a, b) = map(int, input().split())
		if n * b >= k:
			print(-1)
		else:
			lo = 0
			hi = n
			while hi - lo > 1:
				mid = (hi + lo) // 2
				if mid * a + (n - mid) * b < k:
					lo = mid
				else:
					hi = mid
			print(hi if hi * a + (n - hi) * b < k else lo)
main()


def f(ans, k, b, n, a):
	works = True
	r = k
	if ans > n:
		works = False
	elif r > a * ans:
		r -= a * ans
		if not ((r - 1) // b >= n - ans and r > b * (n - ans)):
			works = False
	else:
		works = False
	return works

def bS(l, r, k, b, n, a):
	while True:
		mid = (l + r) // 2
		if r - l == 1:
			break
		if f(mid, k, b, n, a):
			l = mid
		else:
			r = mid
	if f(r, k, b, n, a):
		return r
	return l

def main():
	for _ in range(int(input())):
		(k, n, a, b) = map(int, input().split())
		ans = bS(0, n + 3, k, b, n, a)
		if f(ans, k, b, n, a):
			print(ans)
		else:
			print(-1)
main()


q = int(input())

def calc(x):
	if a * x + b * (n - x) < k:
		return True
	else:
		return False
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		print(-1)
	elif a * n < k:
		print(n)
	else:
		(l, r) = (0, 10 ** 9)
		while r - l > 1:
			mid = (r + l) // 2
			if calc(mid):
				l = mid
			else:
				r = mid
		print(l)


for _ in range(int(input())):
	(p, q, r, s) = map(int, input().split())
	if p <= q * s:
		print(-1)
		continue
	print(max(0, min(q, (p - q * s - 1) // (r - s))))


def is_correct(h1):
	return h1 * a + (n - h1) * b < k
q = int(input())
for req in range(q):
	(k, n, a, b) = map(int, input().split())
	left = -1
	right = n + 1
	while right - left != 1:
		middle = (left + right) // 2
		if is_correct(middle):
			left = middle
		else:
			right = middle
	print(left)


from math import *
t = int(input())
while t:
	t -= 1
	(k, n, a, b) = map(int, input().split())
	rep = (b * n - k + 1) // (b - a)
	if rep >= 0:
		print(min(n, rep))
	else:
		print(-1)


for x in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	p = b * n + 1
	if k >= p:
		print(min((k - p) // (a - b), n))
	else:
		print(-1)


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
for i in range(n):
	(k, n, a, b) = zz()
	t1 = (k - 1) // a
	t2 = (k - t1 * a - 1) // b
	t3 = (k - 1) // b
	if t3 < n:
		print(-1)
		continue
	x = 0
	s = a * n
	temp = s - k + 1
	x = n - temp / (a - b)
	print(min(n, int(x)))


q = int(input())
while q > 0:
	lst = list(map(int, input().split()))
	k = lst[0]
	n = lst[1]
	a = lst[2]
	b = lst[3]
	can_k = k - b * n
	if can_k <= 0:
		print(-1)
		q -= 1
		continue
	p = can_k // (a - b)
	if can_k % (a - b) == 0:
		p -= 1
	if p > n:
		p = n
	print(p)
	q -= 1


import sys
import os
from io import IOBase, BytesIO

def main():
	from math import ceil
	for tc in range(int(input())):
		(k, n, a, b) = get_ints()
		(low, high) = (-1, n)
		while low < high:
			mid = (low + high + 1) // 2
			if mid * a + (n - mid) * b < k:
				low = mid
			else:
				high = mid - 1
		print(low)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


def main():

	def pos(x, a, b, k):
		return a * x + b * (n - x) < k
	for i in range(int(input())):
		(k, n, a, b) = map(int, input().split())
		(left, right) = (-1, n + 1)
		while left + 1 < right:
			mid = (left + right) // 2
			if pos(mid, a, b, k):
				left = mid
			else:
				right = mid
		print(left)
main()


q = int(input())
t1 = q
while t1 != 0:
	arr = list(map(int, str(input()).split(' ')))
	k = arr[0]
	n = arr[1]
	a = arr[2]
	b = arr[3]
	just = 0
	if k <= n * b:
		print(-1)
	else:
		just = (k - n * b - 1) // (a - b)
		print(min(just, n))
	t1 -= 1


turns = int(input())
for i in range(0, turns):
	ent = list(map(int, input().strip().split()))[:4]
	k = ent[0]
	n = ent[1]
	a = ent[2]
	b = ent[3]
	if a - b == 0:
		print('-1')
	else:
		x = (k - b * n) / (a - b)
		if x > n:
			print(n)
		elif x <= 0:
			print('-1')
		elif float(x) == int(x):
			print(int(x - 1))
		else:
			print(int(x))


def poss(x):
	z = k - a * x
	if z // b >= n - x and z != 0 and (z > 0):
		if z % b == 0 and z // b == n - x:
			return False
		return True
	else:
		return False

def bin(st, end):
	while st < end:
		mid = (st + end) // 2
		if poss(mid):
			st = mid + 1
		else:
			end = mid - 1
	if poss(st + 1) and st + 1 <= n:
		return st + 1
	if poss(st):
		return st
	if poss(st - 1) and st - 1 >= 0:
		return st - 1
	return -1
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	z = k // a
	bo = bin(0, min(z, n))
	print(bo)


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	lo = 0
	hi = n

	def check(mi):
		play = a
		now = k - play * mi
		if now < 0:
			return 0
		oth = n - mi
		z = oth - 1
		if now - z * b > b:
			now = now - (z + 1) * b
			if now > 0:
				return 1
			return 0
		return 0
	ans = -1
	while lo <= hi:
		mi = lo + hi >> 1
		if check(mi):
			ans = mi
			lo = mi + 1
		else:
			hi = mi - 1
	print(ans)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	pp = [0] * (limit + 1)
	prime = []
	l[0] = 0
	l[1] = 0
	c = 0
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i] == 1:
			c += 1
		if l[c] == 1:
			pp[i] = 1
	for i in range(1, limit + 1):
		pp[i] += pp[i - 1]
	return pp

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

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

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	(k, n, a, b) = mp()
	z = k // a
	if k % a == 0:
		z -= 1
	if z >= n:
		pr(n)
	else:
		x = k // b
		if k % b == 0:
			x -= 1
		if x >= n:
			c = (k - 1 - n * b) // (a - b)
			pr(c)
		else:
			pr(-1)
for _ in range(inp()):
	solve()


import sys
import math
for _ in range(int(input())):
	(k, n, a, b) = map(int, sys.stdin.readline().split())
	if k - b * n <= 0:
		print(-1)
	else:
		l = 0
		h = n
		while l < h:
			mid = math.ceil((l + h) / 2)
			if k - mid * a > (n - mid) * b:
				l = mid
			else:
				h = mid - 1
		print(h)


s = t = u = v = q = 0
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k == s and n == t and (u == a) and (v == b):
		print(q)
		continue
	(s, t, u, v) = (k, n, a, b)
	if n * b >= k:
		print(-1)
	else:
		(l, h, p) = (0, n, 0)
		while l <= h:
			m = (l + h) // 2
			x = n - m
			if m * a + x * b < k:
				p = m
				l = m + 1
			else:
				h = m - 1
		q = p
		print(p)


import traceback
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import defaultdict as dfd, Counter
from functools import lru_cache
from itertools import accumulate

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

def getsl():
	return input().split()

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	(power, turns, a, b) = getil()

	def check(i):
		rem = power - i * a
		rem -= (turns - i) * b
		return rem > 0
	(lo, hi) = (0, turns)
	while lo < hi:
		mid = (lo + hi) // 2 + 1
		if check(mid):
			lo = mid
		else:
			hi = mid - 1
	return lo if check(lo) else -1
try:
	Test = geti()
	answers = []
	for _ in range(Test):
		ans = main()
		ans = str(ans)
		answers.append(ans)
	print('\n'.join(answers))
except Exception as e:
	print(e)
	traceback.print_exc()


import math
count = int(input())
for i in range(count):
	(k, n, a, b) = map(int, input().split())
	if n * a < k:
		print(n)
	elif n * b < k:
		raz = a - b
		tmp = n * a - k + 1
		num = math.ceil(tmp / raz)
		print(n - num)
	else:
		print(-1)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input()
t = I()
for i in range(0, t):
	(k, n, a, b) = li()
	k = k - n * a
	if k > 0:
		print(n)
		continue
	diff = a - b
	k = -k
	turns = k // diff
	if turns > n:
		print(-1)
	else:
		print(n - turns - 1)


t = int(input())
for z in range(t):
	(k, n, a, b) = [int(x) for x in input().split()]
	ans = 0
	if k - b * n <= 0:
		print(-1)
		continue
	p = b * n
	k -= p
	d = (k - 1) // (a - b)
	ans = min(n, d)
	print(ans)


q = int(input())
while q:
	(k, n, a, b) = map(int, input().split())
	c = 0
	if k - n * b <= 0:
		c = -1
	elif k - n * a > 0:
		c = n
	else:
		c = (k - n * b) / (a - b)
		if int(c) == c:
			c = int(c) - 1
		else:
			c = int(c)
	print(c)
	q = q - 1


t = int(input())
while t:
	(k, n, a, b) = [int(a) for a in input().split(' ')]
	p = (k - b * n) // (a - b)
	diff = (k - b * n) / (a - b) - p
	if p == 0 and diff == 0:
		print('-1')
	elif diff == 0:
		print(max(min(p - 1, n), -1))
	else:
		print(max(min(p, n), -1))
	t -= 1


def main():
	q = int(input())
	for i in range(q):
		(k, n, a, b) = map(int, input().split())
		num = k - b * n
		den = a - b
		if num % den == 0:
			ans = num // den
			ans -= 1
		else:
			ans = num // den
		if ans < 0:
			print(-1)
			continue
		print(min(n, ans))
main()


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_test = RI()
for _ in range(nb_test):
	(has, nb_round, costA, costB) = RMI()
	answer = (costB * nb_round - has + 1) // (costB - costA)
	answer = min(nb_round, answer)
	if answer < 0:
		answer = -1
	print(answer)


def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))
from sys import exit

def solve():
	(n, k, a, b) = getList()
	if n > k * a:
		print(k)
		return
	if n <= k * b:
		print(-1)
		return
	loss = k * a - n
	recv = a - b
	ans = k - loss // recv
	if loss % recv == 0:
		ans -= 1
	else:
		ans -= 1
	print(ans)

def main():
	q = getN()
	for query in range(q):
		solve()
main()


from math import ceil
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	p = n * a
	y = (n * a - k) // (a - b)
	if y + 1 < 0:
		print(n)
	else:
		ans = n - (y + 1)
		if ans < 0:
			print(-1)
		else:
			print(ans)


import math
import sys
for _ in range(int(input())):
	(k, n, a, b) = map(int, sys.stdin.readline().split())
	lowest = b * n
	if k > lowest:
		totol = 0
		cur = k - lowest
		mx = int(math.floor(k * 1.0 / a))
		l = 0
		r = n
		while r > l:
			next = int(math.ceil(1.0 * (l + r) / 2))
			cur = next * a
			last = (n - next) * b
			if k > cur + last:
				l = next
			else:
				r = next - 1
		sys.stdout.write('{}\n'.format(r))
	else:
		print(-1)


def f(k, n, a, b):
	m = (k - n * b) / (a - b)
	if m <= 0:
		return -1
	elif m == int(m):
		if m - 1 >= n:
			return n
		else:
			return m - 1
	elif int(m) >= n:
		return n
	else:
		return int(m)
n = int(input())
c = []
for i in range(n):
	b = input().split()
	c.append(b)
for i in c:
	print(int(f(int(i[0]), int(i[1]), int(i[2]), int(i[3]))))


n = int(input())
for x in range(n):
	(a, b, c, d) = list(map(int, input().split()))
	jam = b * d
	lam = c - d
	ham = a - jam
	if d * b >= a:
		print(-1)
	elif c * b < a:
		print(b)
	elif ham % lam == 0:
		print(int(ham // lam) - 1)
	else:
		print(int(ham // lam))


def main():
	q = int(input())
	for _ in range(q):
		(k, n, a, b) = (int(i) for i in input().split())
		(l, r) = (-1, n + 1)
		while l + 1 < r:
			x = (l + r) // 2
			if x * a + (n - x) * b < k:
				l = x
			else:
				r = x
		x = l
		print(x)
main()


def is_valid(ko, n, a, b):
	k = int(ko)
	turns = (k - 1) // a
	k -= a * ((k - 1) // a)
	turns += (k - 1) // b
	k -= b * ((k - 1) // b)
	if turns < n:
		return False
	return True
q = int(input())
for t in range(q):
	(k, n, a, b) = map(int, input().split())
	on = int(n)
	if not is_valid(k, n, b, b):
		print(-1)
	elif is_valid(k, n, a, b):
		ans = (k - 1) // a
		if ans > n:
			ans = n
		print(ans)
	else:
		ext = n // 2
		upper_bound = n
		lower_bound = 0
		while not upper_bound == lower_bound + 1:
			if is_valid(k - ext * b, n - ext, a, b):
				upper_bound = ext
			else:
				lower_bound = ext
			ext = (lower_bound + upper_bound) // 2
		ans = (k - upper_bound * b - 1) // a
		print(ans)


from sys import stdin
import math
q = int(stdin.readline())
for qq in range(q):
	(k, n, a, b) = [int(x) for x in stdin.readline().rstrip().split()]
	if n * b >= k:
		print(-1)
	else:
		num = k - b * n
		dem = a - b
		div = math.floor(num / dem)
		result = -1
		if num % dem == 0:
			result = div - 1
		else:
			result = div
		if result > n:
			print(n)
		else:
			print(result)


T = int(input())
for _ in range(0, T):
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
	else:
		aval = k - n * b - 1
		diff = a - b
		print(min(aval // diff, n))


q = int(input())
for i in range(q):
	(k, n, a, b) = [int(x) for x in input().split()]
	l = 0
	r = n
	while r - l > 1:
		mid = (l + r) // 2
		x = k - a * (mid - 1)
		if x > a:
			x -= a
			x -= b * (n - mid - 1)
			if x > b:
				x -= b
				if x > 0:
					l = mid
				else:
					r = mid
			else:
				r = mid
		else:
			r = mid
	if k - (n - 1) * a > a and k - n * a > 0:
		print(r)
	elif k - (n - 1) * b > b and k - n * b > 0:
		print(l)
	else:
		print(-1)


from sys import stdin
s = t = u = v = q = 0
for _ in range(int(stdin.readline())):
	(k, n, a, b) = map(int, stdin.readline().split())
	if k == s and n == t and (u == a) and (v == b):
		print(q)
		continue
	(s, t, u, v) = (k, n, a, b)
	if n * b >= k:
		print(-1)
	else:
		(l, h, p) = (0, n, 0)
		while l <= h:
			m = (l + h) // 2
			x = n - m
			if m * a + x * b < k:
				p = m
				l = m + 1
			else:
				h = m - 1
		q = p
		print(p)


import math
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		print(-1)
	else:
		u = math.ceil((k - b * n) / (a - b) - 1)
		if u > n:
			print(n)
		else:
			print(u)


q = int(input())
for i in range(q):
	k_n_a_b = [int(i) for i in input().split()]
	result = -1
	if k_n_a_b[1] * k_n_a_b[-1] < k_n_a_b[0]:
		aux = (k_n_a_b[0] - k_n_a_b[1] * k_n_a_b[-1] - 1) // (k_n_a_b[-2] - k_n_a_b[-1])
		if aux < k_n_a_b[1]:
			result = aux
		else:
			result = k_n_a_b[1]
	print(result)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(k, n, a, b) = value()
	k -= 1
	if k - b * n < 0:
		print(-1)
	else:
		print(min((k - b * n) // (a - b), n))


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	x = (k - n * b) // (a - b)
	if k <= n * b:
		print(-1)
	elif (k - n * b) % (a - b) == 0:
		print(min(x - 1, n))
	else:
		print(min(x, n))


t = int(input())
while t:
	t -= 1
	(k, n, a, b) = map(int, input().split())
	if n * b >= k:
		print(-1)
	elif n * a < k:
		print(n)
	else:
		k -= n * b
		res = a - b
		if k % res == 0:
			print(min(n, k // res - 1))
		else:
			print(min(n, k // res))


def bSearch(k, n, a, b):
	l = 0
	r = n
	while l + 1 < r:
		t = (l + r) // 2
		if k - a * t <= b * (n - t):
			r = t - 1
		else:
			l = t
	if k - a * r > b * (n - r):
		return r
	elif k - a * l > b * (n - l):
		return l
	else:
		return -1
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	print(bSearch(k, n, a, b))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	count = (a - b * d - 1) / (c - d)
	if count < 0:
		print(-1)
	else:
		print(min(int(count), b))


for i in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k - b * n <= 0:
		print('-1')
	else:
		(low, high) = (0, n)
		ans = 0
		while low <= high:
			mid = (low + high) // 2
			if k - (mid * b + (n - mid) * a) > 0:
				ans = max(ans, n - mid)
				high = mid - 1
			else:
				low = mid + 1
		print(ans)


for i in range(int(input())):
	(k, n, a, b) = [int(x) for x in input().split()]
	if k - n * b <= 0:
		print(-1)
		continue
	lo = 0
	hi = n
	mid = (lo + hi) // 2
	while lo <= hi:
		mid = (lo + hi) // 2
		cost = mid * a + (n - mid) * b
		if k - cost > 0:
			lo = mid + 1
			if k - cost - a + b <= 0:
				break
		else:
			hi = mid - 1
	mx = 0
	for i in range(max(mid - 5, 0), mid + 5):
		cost = i * a + (n - i) * b
		if k - cost > 0:
			mx = i
	print(min(n, mx))


q = int(input())
ans = []
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if a == b:
		if a * n <= k:
			ans.append(str(-1))
		else:
			ans.append(str(n))
	else:
		left = b * n
		if k <= left:
			ans.append(str(-1))
			continue
		ans_ = (k - left) // (a - b)
		if (k - left) % (a - b) == 0:
			ans_ -= 1
		if ans_ > n:
			ans_ = n
		ans.append(str(ans_))
print('\n'.join(ans))


q = int(input())
res = []
for x in range(q):
	[k, n, a, b] = [int(i) for i in input().split()]
	if k <= b * n:
		res.append(-1)
	else:
		r = min(int((k - b * n) / (a - b)), n)
		while a * r + b * (n - r) < k and r <= n:
			r += 1
		r -= 1
		res.append(r)
for i in res:
	print(i)


import math
q = int(input())
for _ in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	x = max(0, int(math.ceil((n * a - (k - 1)) / (a - b))))
	ans = n - x
	if ans < 0:
		ans = -1
	print(ans)


q = int(input())
for I in range(q):
	(k, n, a, b) = [int(i) for i in input().split()]
	tot = n * b
	fin = -1
	if k > tot:
		left = k - tot - 1
		fin = left // (a - b)
		if n < fin:
			fin = n
	print(fin)


def Bsearch(k, a, b, n):
	ans = -1
	(l, r) = (0, k // a)
	while l <= r:
		mid = l + (r - l) // 2
		v = (k - mid * a) // b
		if mid + v > n:
			ans = mid
			l = mid + 1
		elif mid + v == n and k - v * b - a * mid > 0:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return min(ans, n)
for tt in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	s = Bsearch(k, a, b, n)
	print(s)


import sys
input = sys.stdin.readline
Q = int(input())
for _ in range(Q):
	(K, N, A, B) = map(int, input().split())
	if B * N >= K:
		print(-1)
	elif A * N < K:
		print(N)
	else:
		print(-(-(K - B * N) // (A - B)) - 1)


import sys
for f in range(int(input())):
	(k, n, a, b) = [int(i) for i in sys.stdin.readline().split()]
	k -= 1
	q = k - n * b
	if q < 0:
		print(-1)
	else:
		print(min(q // (a - b), n))


def binser(a, b, n, k, l, r):
	mid = (l + r) // 2
	y = n - mid
	if l >= r:
		return l
	if a * mid + b * y >= k:
		return binser(a, b, n, k, l, mid - 1)
	return binser(a, b, n, k, mid + 1, r)
q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		print(-1)
		continue
	ans = binser(a, b, n, k, 0, n)
	while a * ans + b * (n - ans) >= k:
		ans -= 1
	print(ans)


def f(k, n, a, b):
	d = k - n * b
	if k > n * a:
		return n
	elif d <= 0:
		return -1
	else:
		return d // (a - b) - 1 if d % (a - b) == 0 else d // (a - b)
t = int(input())
for test in range(t):
	(k, n, a, b) = map(int, input().split())
	print(f(k, n, a, b))


def main():
	n = int(input())
	for i in range(n):
		(k, n, a, b) = map(int, input().split())
		if k // b < n or (k // b == n and k % b == 0):
			print(-1)
		else:
			l = -1
			r = n + 1
			for w in range(30):
				copy = k
				bet = (l + r) // 2
				copy -= bet * a
				if b * (n - bet) >= copy:
					r = bet
				else:
					l = bet
			if l < 0:
				l = 0
			print(l)
main()


answer = []
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		answer.append('-1')
	else:
		k -= n * b
		answer.append(str(min((k - 1) // (a - b), n)))
print('\n'.join(answer))


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
q = ii1()
for _ in range(q):
	(k, n, a, b) = iia()
	if k - n * a > 0:
		print(n)
	elif k - n * b <= 0:
		print(-1)
	else:
		turns = (k - n * b - 1) // (a - b)
		print(turns)


import math
tt = int(input())
while tt:
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		print(-1)
	elif k == a * n:
		print(n - 1)
	elif k > n * a:
		print(n)
	else:
		re1 = k - b * n
		re2 = a - b
		re = re1 // re2
		rt = re1 % re2
		if rt == 0:
			re -= 1
		print(re)
	tt -= 1


import math
import random
q = int(input())

def run(q):
	for _ in range(q):
		(k, n, a, b) = [int(x) for x in input().split()]
		temp = (k - b * n - 1) // (a - b)
		if temp >= 0:
			print(min(n, temp))
		else:
			print(-1)
run(q)


def valid(p):
	if p * a + (n - p) * b < k:
		return 1
	return 0
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	x = -1
	w = n + 1
	while w >= 1:
		while valid(w + x) == 1 and w + x <= n:
			x += w
		w //= 2
	print(x)


from math import ceil
t = int(input())
for _ in range(t):
	(k, n, a, b) = map(int, input().split())
	x = min(max(0, ceil((k - n * b) / (a - b)) - 1), n)
	if k - x * a - (n - x - 1) * b > b and k - (x + 1) * a - (n - x - 1) * b > 0 and (x < n):
		print(x + 1)
	elif k - x * a - (n - x - 1) * b > b and k - x * a - (n - x) * b > 0:
		print(x)
	elif k - (x - 1) * a - (n - x) * b > b and k - x * a - (n - x) * b > 0 and (x > 1):
		print(x)
	else:
		print(-1)


for TT in range(1, int(input()) + 1):
	(k, n, a, b) = map(int, input().split())
	x = (k - n * b + (a - b - 1)) // (a - b) - 1
	x = min(x, n)
	x = max(x, -1)
	print(x)


import math
import sys

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
q = ii()
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if k - n * b <= 0:
		print(-1)
	elif k - n * a > 0:
		print(n)
	else:
		l = 0
		r = k // a
		ans = -1
		while l <= r:
			mid = l + (r - l) // 2
			if k - mid * a - (n - mid) * b > 0:
				ans = mid
				l = mid + 1
			else:
				r = mid - 1
		print(ans)


q = int(input())
for i in range(q):
	(k, n, a, b) = (int(s) for s in input().split())
	z = k - n * b
	if z <= 0:
		print(-1)
		continue
	print(min(n, (z - 1) // (a - b)))


def check(k, n, a, b, cnt):
	rest = k
	rest -= cnt * a
	if rest > 0:
		rest -= (n - cnt) * b
		return rest > 0
	else:
		return False
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	left = -1
	right = n + 1
	while right - left > 1:
		mid = (right + left) // 2
		if check(k, n, a, b, mid):
			left = mid
		else:
			right = mid
	print(left)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	ans = (k - b * n - 1) // (a - b)
	if b * n >= k:
		print(-1)
	else:
		print(min(ans, n))


def main():
	q = int(input())
	for _ in range(q):
		[k, n, a, b] = list(map(int, input().split()))
		turns = n
		charge = k
		low = 0
		high = n
		ans = 0
		while low <= high:
			mid = (low + high) // 2
			final = (n - mid) * b + mid * a
			if final < charge:
				ans = mid
				low = mid + 1
			else:
				high = mid - 1
		if k - n * b <= 0:
			ans = -1
		print(ans)
main()


from sys import stdin
for _ in range(int(stdin.readline())):
	(k, n, a, b) = [int(x) for x in stdin.readline().split()]
	q = k // b
	if q < n:
		print(-1)
		continue
	ans = (k - n * b) // (a - b)
	if ans <= n and k - ans * a - (n - ans) * b == 0:
		ans -= 1
	print(min(ans, n))


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def factors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def good(k, n, a, b, mid):
	count = 0
	k = k - mid * a
	if k == 0 or k < 0:
		return False
	else:
		count += mid
	if count > n:
		return False
	if k % b == 0:
		count += k // b - 1
	else:
		count += k // b
	if count >= n:
		return True
	return False
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	ans = -1
	l = 0
	r = 10 ** 9 + 1
	while l <= r:
		mid = (l + r) // 2
		if good(k, n, a, b, mid) == True:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	print(ans)


T = int(input())
test = 0
while test < T:
	arr = input()
	(K, N, a, b) = [int(num) for num in arr.split(' ')]
	if N * b >= K:
		print(-1)
	else:
		s = N * b
		d = a - b
		m = (K - 1 - s) // d
		if m <= N:
			print(m)
		else:
			print(N)
	test += 1


q = int(input())
for i in range(q):
	inp = list(map(int, input().split()))
	k = inp[0]
	n = inp[1]
	a = inp[2]
	b = inp[3]
	if k <= n * b:
		print(-1)
	else:
		dist = k - n * b
		diff = a - b
		if dist % diff == 0:
			if dist // diff - 1 < n:
				print(dist // diff - 1)
			else:
				print(n)
		elif dist // diff < n:
			print(dist // diff)
		else:
			print(n)


import math

def main():
	for _ in range(int(input())):
		(k, n, a, b) = list(map(int, input().split()))
		a = math.ceil((k - b * n) / (a - b)) - 1
		if a >= 0:
			a = a if a < n else n
			print(a)
		else:
			print(-1)
main()


def solve(charge, n, a, b):
	test = (charge - n * b) / (a - b)
	if test != int(test):
		if test < 0:
			return -1
		res = int(test)
	else:
		if test < 1:
			return -1
		res = int(test) - 1
	return min(res, n)
tests = int(input())
for _ in range(tests):
	(charge, n, a, b) = [int(x) for x in input().split()]
	print(solve(charge, n, a, b))


def ispossible(charge, playcost, lowplaycost, playcnt, allcnt):
	return charge > playcost * playcnt + lowplaycost * (allcnt - playcnt)

def solution():
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		return -1
	l = 0
	r = n + 1
	while r - l > 1:
		m = (r + l) // 2
		if ispossible(k, a, b, m, n) == True:
			l = m
		else:
			r = m
	return l

def main():
	test = int(input())
	for i in range(test):
		print(solution())
	return
main()


test = int(input())
for i in range(test):
	(k, n, a, b) = map(int, input().split())
	if k - b * n <= 0:
		print(-1)
	else:
		res = int((k - b * n) / (a - b))
		if (k - b * n) % (a - b) == 0:
			res -= 1
		print(min(res, n))


for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	l = 0
	r = n
	ans = 0
	if b * n >= k:
		print(-1)
		continue
	while l <= r:
		mid = (l + r) // 2
		if a * mid + b * (n - mid) < k:
			l = mid + 1
			ans = mid
		else:
			r = mid - 1
	print(ans)


q = int(input())
for _ in range(q):
	(k, n, a, b) = map(int, input().split())
	if b * n >= k:
		print(-1)
		continue
	L = 0
	R = n
	while R - L > 1:
		M = (L + R) // 2
		if a * M + b * (n - M) < k:
			L = M
		else:
			R = M
	if a * R + b * (n - R) < k:
		print(R)
	else:
		print(L)


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	if k <= b * n:
		print(-1)
	else:
		ans = (k - b * n) / (a - b)
		ans2 = (k - b * n) // (a - b)
		if abs(ans - ans2) <= 1e-09:
			print(min(ans2 - 1, n))
		else:
			print(min(ans2, n))


q = int(input())
for i in range(q):
	(k, n, a, b) = [int(i) for i in input().split(' ')]
	result = float(k - b * n) / (a - b)
	if b * n >= k:
		print(-1)
		continue
	if result == int(result):
		result = int(result) - 1
	else:
		result = int(result)
	print(min(n, result))


from math import ceil
for _ in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	res = k - n * a
	if res > 0:
		print(n)
	else:
		plays = ceil((1 - res) / (a - b))
		if plays > n:
			print(-1)
		else:
			print(n - plays)


import math
q = int(input())
for qq in range(q):
	(k, n, a, b) = map(int, input().split())
	x = math.ceil(min(k / a, (k - n * b) / (a - b))) - 1
	if x < 0:
		print(-1)
	else:
		print(min(n, int(x)))


from sys import stdin, stdout
for i in range(int(stdin.readline())):
	temp = list(map(int, stdin.readline().split()))
	(k, n, a, b) = (temp[0], temp[1], temp[2], temp[3])
	rem = k - (b + 1 + b * (n - 1))
	if rem < 0:
		print(-1)
	else:
		c = rem // (a - b)
		if c > n:
			c = n
		print(c)


n = int(input())
for i in range(n):
	(k, n, a, b) = input().split()
	k = int(k)
	n = int(n)
	a = int(a)
	b = int(b)
	if n * b >= k:
		print(-1)
	else:
		ans = (k - n * b) / (a - b)
		if int((k - n * b) / (a - b)) == (k - n * b) / (a - b):
			ans = int((k - n * b) / (a - b)) - 1
		ans = min(ans, n)
		print(int(ans))


t = int(input())
while t > 0:
	(k, n, a, b) = map(int, input().split())
	r = k
	c = 0
	z = 0
	x = k - 1 - n * b
	x = x // (a - b)
	if x < 0:
		print('-1')
	else:
		x = min(x, n)
		print(x)
	t -= 1


m = int(input())
for ii in range(m):
	(k, n, a, b) = [int(i) for i in input().split()]
	if k <= n * b:
		print(-1)
	else:
		delta = a - b
		new = k - b * n
		print(min((new - 1) // delta, n))


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	temp = n
	k -= 1
	obzh = k // b
	if obzh < n:
		print(-1)
		continue
	l = 0
	r = n + 1
	while r - l > 1:
		m = (l + r) // 2
		p = (k - m * a) // b
		if m + p >= n:
			l = m
		else:
			r = m
	print(min(temp, l))


def check(k, n, a, b, mid):
	if k > mid * a + (n - mid) * b:
		return True
	return False
q = int(input())
for _ in range(q):
	(k, n, a, b) = list(map(int, input().split()))
	if k - b * n > 0:
		(start, end) = (0, n)
		while start <= end:
			mid = (start + end) // 2
			(p, q) = (check(k, n, a, b, mid), check(k, n, a, b, mid + 1))
			if p == True and mid + 1 <= n and (q == False):
				print(mid)
				break
			if p == True and mid + 1 > n:
				print(mid)
				break
			if p == False:
				end = mid - 1
			if p == True and mid + 1 <= n and (q == True):
				start = mid + 1
	else:
		print(-1)


print('\n'.join(((lambda a: str(-1 if a[0] <= a[1] * a[3] else min((a[0] - a[1] * a[3] - 1) // (a[2] - a[3]), a[1])))(list(map(int, input().split()))) for _ in range(int(input())))))


q = int(input())
for test in range(q):
	(k, n, a, b) = map(int, input().split(' '))
	num = k - n * b
	den = a - b
	if num <= 0:
		print(-1)
	elif num % den == 0:
		print(min(n, num // den - 1))
	else:
		print(min(n, num // den))


def f(x, n, a, b, k):
	return k - (a * x + b * (n - x))

def func():
	(k, n, a, b) = map(int, input().split())
	if k <= n * b:
		return -1
	l = 0
	r = n
	while r - l > 1:
		m = (l + r) // 2
		if f(m, n, a, b, k) > 0:
			l = m
		else:
			r = m
	if f(r, n, a, b, k) > 0:
		return r
	return l
q = int(input())
for i in range(q):
	print(func())


def is_possible(num, a, b, n, k):
	return k - num * a - (n - num) * b > 0
amount = int(input())
for i in range(amount):
	(k, n, a, b) = [int(s) for s in input().split()]
	left = -1
	right = n + 1
	while right - left > 1:
		middle = (right + left) // 2
		if is_possible(middle, a, b, n, k):
			left = middle
		else:
			right = middle
	print(left)


q = int(input())
for i in range(q):
	(k, n, a, b) = list(map(int, input().strip().split()))
	if b * n >= k:
		print(-1)
	else:
		x = (k - n * b) // (a - b)
		if (k - n * b) % (a - b) == 0:
			print(min(x - 1, n))
		else:
			print(min(x, n))


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	(k, n, a, b) = map(int, input().split())
	c = 0
	if b * n >= k:
		print(-1)
	else:
		l = 0
		r = n + 1
		while l < r - 1:
			m = l + abs(r - l) // 2
			if m * a + (n - m) * b < k:
				l = m
			else:
				r = m
		print(l)


def computer_game(k, n, a, b):
	k -= n * a
	if k > 0:
		return n
	k = -k
	k += 1
	difference = a - b
	moves = (k + difference - 1) // difference
	if moves > n:
		return -1
	else:
		return n - moves
m = int(input())
lst = list()
for j in range(m):
	(K, N, A, B) = [int(x) for x in input().split()]
	lst.append(computer_game(K, N, A, B))
for elem in lst:
	print(elem)


q = int(input())
for i in range(q):
	(k, n, a, b) = map(int, input().split())
	c = k - n * a
	if c > 0:
		print(n)
	else:
		from math import *
		m = ceil((-c + 1) / (a - b))
		if m > n:
			print(-1)
		else:
			print(n - m)


def chk(fa, fb, fc, fn, fk):
	return fa * fc + fb * (fn - fc) < fk
for q in range(int(input())):
	(k, n, a, b) = list(map(int, input().split()))
	if a * n < k:
		print(n)
		continue
	(c, d, ans) = (n // 2, n, '')
	if c == 0:
		if b * n >= k:
			print(-1)
		else:
			print(0)
		continue
	while not chk(a, b, c, n, k):
		d = c
		c = d // 2
		if c == 0:
			if b * n >= k:
				print(-1)
			else:
				print(0)
			break
	else:
		while chk(a, b, c, n, k):
			if c == (d + c) // 2:
				print(c)
				break
			else:
				e = c
				c = (d + c) // 2
				if chk(a, b, c, n, k):
					continue
				else:
					d = c
					c = e


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	k = int(p[0])
	K = k
	n = int(p[1])
	CC = n
	a = int(p[2])
	b = int(p[3])
	T = min(a, b)
	if k % T == 0:
		H = k // T - 1
	else:
		H = k // T
	if n > H:
		print(-1)
	else:
		if k % a == 0:
			A = k // a - 1
		else:
			A = k // a
		B = k - A * a
		k = B
		n = n - A
		if n <= 0:
			if A >= CC:
				print(CC)
			else:
				print(A)
		else:
			G = b * n
			if k > G:
				if A >= CC:
					print(CC)
				else:
					print(A)
			else:
				V = -99999
				GG = 1
				MM = G - k
				LL = a - b
				XX = MM // LL + 1
				A = A - XX
				if A >= CC:
					print(CC)
				else:
					print(A)


def main():
	q = int(input())
	for i in range(0, q):
		l = input().split()
		k = int(l[0])
		n = int(l[1])
		a = int(l[2])
		b = int(l[3])
		if k <= n * b:
			print(-1)
		else:
			max = k - n * b
			r = a - b
			num = max // r
			if num > n:
				print(n)
			elif max == num * r:
				print(num - 1)
			else:
				print(num)
main()


def main():
	q = int(input())
	for qi in range(q):
		(k, n, a, b) = map(int, input().split())
		if k - n * b <= 0:
			print(-1)
			continue
		else:
			d_n = k - n * b
			d_d = a - b
			if d_n % d_d == 0:
				print(min(d_n // d_d - 1, n))
			else:
				print(min(d_n // d_d, n))
main()


import time
q = int(input())
ans = []
start = time.time()
for i in range(q):
	(k, n, a, b) = (int(i) for i in input().split())
	mn = n * b
	if mn >= k:
		ans.append(-1)
	else:
		d = a - b
		z = k - mn - 1
		ans.append(min(z // d, n))
for i in range(q):
	print(ans[i])
finish = time.time()