Chef has allocated himself a budget of P rupees to buy Diwali crackers. There are only 3 types of crackers available in the market and each type of cracker can be bought any number of times.

1. Fuljhari, where each costs a rupees
2. Anar, where each costs b rupees
3. Chakri, where each costs c rupees

The crackers have the following interesting properties:-
A Fuljhari can be lit on its own 
To light an Anar, you will need x Fuljharis
To light a Chakri, you will need y Fuljharis

What's the maximum total of Anars and Chakris that Chef can light up with his given budget.

------ Input Format ------ 

- First line of input will contain T, the number of test cases. Then the test cases follow.
- Each test case contains of a single line of input, six integers P, a, b, c, x and y.

------ Output Format ------ 

For each test case, output in a single line the maximum total of Anars and Chakris Chef can light up.

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$1 ≤ P, a, b, c, x, y ≤ 10^{9}$

----- Sample Input 1 ------ 
3
100 5 5 10 4 8
16 2 2 2 1 1
55 1 2 3 4 5
----- Sample Output 1 ------ 
4
4
9
----- explanation 1 ------ 
Test case $1$:
- Chef will buy $16$ Fuljhari's and $4$ Anar's which in total costs him $16 \cdot 5 + 4 \cdot 5 = 100$ rupees. 
- Next, he uses $16$ Fuljhari's to light $\frac{16}{4} = 4$ Anar's. 
- Since all the Fuljhari's are over, he can't light up any Chakri's.
- So in total, he is able to light up $4 + 0 = 4$ Anar's and Chakri's.
- There is no other allocation giving a better answer than this.

Test case $2$:
- Chef will buy $4$ Fuljhari's, $2$ Anar's and $2$ Chakri's which in total costs him $4 \cdot 2 + 2 \cdot 2 + 2 \cdot 2 = 16$ rupees. 
- Next, he uses $2$ Fuljhari's to light $\frac{2}{1} = 2$ Anar's. 
- Next, he uses $2$ Fuljhari's to light $\frac{2}{1} = 2$ Chakri's. 
- So in total, he is able to light up $2 + 2 = 4$ Anar's and Chakri's.
- The other possible allocation could be buying $4$ Fuljhari's, $3$ Anar's, and $1$ Chakri.

Difficulty: MEDIUM
Tags: Mathematics

Starter code:

Solutions:
for j in range(int(input())):
	(p, x, y, z, a, b) = map(int, input().split())
	y = x * a + y
	z = x * b + z
	r = min(y, z)
	print(int(p / r))


for i in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	b = a * x + b
	c = a * y + c
	r = min(b, c)
	print(int(p / r))


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	A = a * x + b
	C = a * y + c
	m = min(A, C)
	print(p // m)


t = int(input())
for _ in range(t):
	(Amt, a, b, c, x, y) = map(int, input().split())
	a1 = b + a * x
	a2 = c + a * y
	m = min(a1, a2)
	print(Amt // m)


for x in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	t = p // (b + x * a)
	t += (p - t * (b + x * a)) // (c + y * a)
	r = p // (c + y * a)
	r += (p - r * (c + y * a)) // (b + x * a)
	print(max(t, r))


T = int(input())
for i in range(T):
	(P, a, b, c, x, y) = map(int, input().split())
	cost = min(c + y * a, b + x * a)
	print(P // cost)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	a = l[1] * l[4] + l[2]
	f = l[1] * l[5] + l[3]
	if a <= f:
		print(l[0] // a)
	else:
		print(l[0] // f)


for ra in range(int(input())):
	(dd, f, u, c, ra, md) = map(int, input().split())
	t = dd // (u + ra * f)
	t += (dd - t * (u + ra * f)) // (c + md * f)
	jd = dd // (c + md * f)
	jd += (dd - jd * (c + md * f)) // (u + ra * f)
	print(max(t, jd))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	anar = l[1] * l[4] + l[2]
	fuli = l[1] * l[5] + l[3]
	if anar <= fuli:
		print(l[0] // anar)
	else:
		print(l[0] // fuli)


tests = int(input())
for i in range(tests):
	(P, a, b, c, x, y) = map(int, input().split())
	each_anar = b + x * a
	each_chakri = c + y * a
	print(max(P // each_anar, P // each_chakri))


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	anar = a * x + b
	chakri = a * y + c
	sumi = 0
	if anar < chakri:
		sumi = p // anar
		p = p - sumi * anar
		sumi += p // chakri
	else:
		sumi = p // chakri
		p = p - sumi * chakri
		sumi += p // anar
	print(sumi)


t = int(input())
for i in range(t):
	(p, a, b, c, x, y) = map(int, input().split())
	z1 = b + a * x
	z2 = c + y * a
	if z1 > z2:
		print(p // z2)
	else:
		print(p // z1)


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	d = x * a + b
	e = y * a + c
	a1 = p // d
	a2 = p // e
	print(a1 if a1 >= a2 else a2)


for t in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	z = min(x * a + b, y * a + c)
	print(p // z)


import sys
for x in range(int(input())):
	(p, a, b, c, x, y) = map(int, sys.stdin.readline().strip().split())
	print(p // min(x * a + b, y * a + c))


for x in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	aa = x * a + b
	bb = y * a + c
	print(p // min(aa, bb))


for _ in range(int(input())):
	(P, a, b, c, x, y) = map(int, input().split())
	b = b + a * x
	c = c + a * y
	k = min(b, c)
	print(P // k)


t = int(input())
for j in range(t):
	(p, a, b, c, x, y) = map(int, input().split())
	r = b + x * a
	s = c + y * a
	v = min(r, s)
	print(p // v)


t = int(input())
for i in range(t):
	(p, a, b, c, x, y) = map(int, input().split())
	num = min(b + a * x, c + a * y)
	print(p // num)


import sys

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

def solve():
	(p, a, b, c, x, y) = get_ints()
	print(int(p / min(x * a + b, y * a + c)))
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	(P, a, b, c, x, y) = map(int, input().split())
	res = max(P // (a * x + b), P // (a * y + c))
	print(res)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	k = min(l[2] + l[4] * l[1], l[3] + l[5] * l[1])
	print(l[0] // k)


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	cost_anar = b + x * a
	cost_chakri = c + y * a
	print(p // min(cost_anar, cost_chakri))


t = int(input())
for i in range(t):
	(amount, a, b, c, x, y) = map(int, input().split())
	b = a * x + b
	c = a * y + c
	if b > c:
		print(amount // c)
	else:
		print(amount // b)


import sys
import bisect
inp = sys.stdin.readline

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

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(inp())):
	(p, a, b, c, x, y) = map(int, input().split())
	b += x * a
	c += y * a
	print(p // min(b, c))


try:
	for _ in range(int(input())):
		(p, a, b, c, x, y) = list(map(int, input().split()))
		print(p // min(x * a + b, y * a + c))
except:
	pass


t = int(input())
for i in range(t):
	(a, b, c, d, e, f) = map(int, input().split())
	s = b * e + c
	x = b * f + d
	m = min(s, x)
	print(a // m)


t = int(input())
for x in range(t):
	(a, b, c, d, e, f) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	e = int(e)
	f = int(f)
	fuljhari = b * e + c
	chakris = b * f + d
	r = min(fuljhari, chakris)
	print(a // r)


t = int(input())
for i in range(t):
	(a, b, c, d, e, f) = map(int, input().split())
	a1 = e * b + c
	c1 = f * b + d
	if a1 > c1:
		ans = a // c1
	else:
		ans = a // a1
	print(ans)


for _ in range(int(input())):
	(p, a, b, c, x, y) = list(map(int, input().split()))
	anar = b + x * a
	chakri = c + y * a
	ans = p / min(anar, chakri)
	print(int(ans))


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	ana = a[4] * a[1] + a[2]
	ck = a[5] * a[1] + a[3]
	one = min(ana, ck)
	print(a[0] // one)


for _ in range(int(input())):
	i1 = input().split()
	(P, a, b, c, x, y) = (int(i1[0]), int(i1[1]), int(i1[2]), int(i1[3]), int(i1[4]), int(i1[5]))
	anar = 0
	rocket = 0
	cost_of_one_anar_with_fuljharis = b + x * a
	cost_of_one_rocket_with_fuljharis = c + y * a
	if cost_of_one_anar_with_fuljharis < cost_of_one_rocket_with_fuljharis:
		anar += P // cost_of_one_anar_with_fuljharis
	else:
		rocket += P // cost_of_one_rocket_with_fuljharis
	print(anar + rocket)


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	n1 = p // (x * a + b)
	n2 = p // (y * a + c)
	print(max(n1, n2))


t = int(input())
for i in range(0, t):
	val = input().split()
	for i in range(6):
		val[i] = int(val[i])
	c1 = val[1] * val[4] + val[2]
	c2 = val[1] * val[5] + val[3]
	print(val[0] // c1) if c1 < c2 else print(val[0] // c2)


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split(' '))
	total_1 = x * a + b
	total_2 = y * a + c
	maxi = 0
	if total_1 <= total_2:
		maxi = p // total_1
	else:
		maxi = p // total_2
	print(maxi)


for _ in range(int(input())):
	(P, a, b, c, x, y) = map(int, input().split(' '))
	num1 = x * a + b
	num2 = y * a + c
	ans = 0
	if num1 <= num2:
		ans = P // num1
	else:
		ans = P // num2
	print(ans)


for _ in range(int(input())):
	(p, a, b, c, x, y) = tuple(map(int, input().split()))
	anar = b + x * a
	chari = c + y * a
	if anar <= chari:
		print(p // anar)
	else:
		print(p // chari)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	(p, a, b, c, x, y) = list(map(int, input().split()))
	a1 = p // (a * y + c)
	a2 = p // (a * x + b)
	print(max(a1, a2))


for j in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	anar = x * a + b
	chakri = y * a + c
	count = 0
	if anar < chakri:
		count += int(p / anar)
		p -= int(p / anar)
	elif anar == chakri:
		if x > y:
			count += int(p / chakri)
			p -= int(p / chakri)
		elif y < x:
			count += int(p / anar)
			p -= int(p / anar)
		elif b > c:
			count += int(p / chakri)
			p -= int(p / chakri)
		else:
			count += int(p / anar)
			p -= int(p / anar)
	else:
		count += int(p / chakri)
		p -= int(p / chakri)
	print(count)


for i in range(int(input())):
	(p, a, b, c, x, y) = [int(x) for x in input().split()]
	anar = x * a + b
	chakri = y * a + c
	print(max(p // anar, p // chakri))


import sys
MOD = 1000000007

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

def ii():
	return int(inp())

def iis():
	return [int(i) for i in inp().split()]

def solve():
	(p, a, b, c, x, y) = iis()
	return p // min(a * x + b, a * y + c)
t = ii()
for _ in range(t):
	print(solve())


def doors(P, a, b, c, x, y):
	anar_1 = b + a * x
	chakri_1 = c + a * y
	cnt = 0
	if anar_1 <= chakri_1:
		return P // anar_1
	else:
		return P // chakri_1
t = int(input())
for i in range(t):
	(P, a, b, c, x, y) = map(int, input().split())
	print(doors(P, a, b, c, x, y))


T = int(input())
for t in range(T):
	(P, A, B, C, X, Y) = [int(k) for k in input().split()]
	a = B + X * A
	b = C + Y * A
	print(P // min(a, b))


t = int(input())
for _ in range(0, t):
	(P, a, b, c, x, y) = map(int, input().split())
	costa = b + x * a
	costc = c + y * a
	cost = min(costa, costc)
	maxac = P // cost
	print(maxac)


t = int(input())
for _ in range(t):
	(p, a, b, c, x, y) = map(int, input().split())
	cost_of_anar = b + x * a
	cost_of_chakri = c + y * a
	cost = min(cost_of_chakri, cost_of_anar)
	ans = p // cost
	print(ans)


def func():
	(p, a, b, c, x, y) = map(int, input().split())
	ac = b + x * a
	cc = c + y * a
	if ac < cc:
		acnt = p // ac
		ccnt = (p - acnt * ac) // cc
		print(acnt + ccnt)
	else:
		ccnt = p // cc
		acnt = (p - ccnt * cc) // ac
		print(acnt + ccnt)
t = int(input())
for i in range(t):
	func()


t = int(input())
for i in range(t):
	ls = [int(x) for x in input().split(' ')]
	P = ls[0]
	a = ls[1]
	b = ls[2]
	c = ls[3]
	x = ls[4]
	y = ls[5]
	print(P // int(min(x * a + b, y * a + c)))


t = int(input())
for _ in range(t):
	(P, a, b, c, x, y) = map(int, input().split())
	one1 = a * x + b
	one2 = a * y + c
	if one1 < one2:
		ans = P // one1
	else:
		ans = P // one2
	print(ans)


t = int(input())
for _ in range(t):
	(p, a, b, c, x, y) = map(int, input().split())
	c1 = x * a + b
	c2 = y * a + c
	mc = min(c1, c2)
	print(p // mc)


for tcase in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	print(p // min(b + a * x, c + a * y))


for _ in range(int(input())):
	(p, a, b, c, x, y) = list(map(int, input().split()))
	m1 = x * a + b
	m2 = y * a + c
	if m1 < m2:
		print(p // m1)
	else:
		print(p // m2)


def crackers_blast(p, a, b, c, x, y):
	quantity1 = p // (x * a + b)
	balance_quantity1 = p % (x * a + b)
	quantity1 += balance_quantity1 // (y * a + c)
	quantity2 = p // (y * a + c)
	balance_quantity2 = p % (y * a + c)
	quantity2 += balance_quantity2 // (x * a + b)
	return max(quantity1, quantity2)
t = int(input())
while t > 0:
	t -= 1
	(p, a, b, c, x, y) = map(int, input().split())
	print(crackers_blast(p, a, b, c, x, y))


import sys
import math
import heapq
from collections import defaultdict as dd
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key as ctk
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(2 * 10 ** 5 + 1)

def comparator(x, y):
	if x[0] == y[0]:
		return x[1] - y[1]
	return True

def ncr(n, r):
	if n < r:
		return 0
	return fc[n] * pow(fc[r] * fc[n - r] % mod, mod - 2, mod) % mod
T = int(input())
for _ in range(T):
	(p, a, b, c, x, y) = map(int, input().split())
	print(max(p // (a * x + b), p // (a * y + c)))


T = int(input())
for _ in range(T):
	(P, a, b, c, x, y) = map(int, input().split())
	canar = b + x * a
	cchakri = c + y * a
	anar = P // canar
	lanar = P - anar * canar
	chakria = lanar // cchakri
	chakri = P // cchakri
	lchakri = P - chakri * cchakri
	anarc = lchakri // canar
	print(max(anar + chakria, chakri + anarc))


T = int(input())
val = 0
while val < T:
	(P, a, b, c, x, y) = [int(x) for x in input().split()]
	cost_Anar = b + x * a
	cost_Chakri = c + y * a
	print(P // min(cost_Anar, cost_Chakri))
	val += 1


t = int(input())
for _ in range(t):
	(p, a, b, c, x, y) = map(int, input().split())
	anar = x * a + b
	chakri = y * a + c
	r = min(anar, chakri)
	print(p // r)


try:
	for _ in range(int(input())):
		(P, a, b, c, x, y) = map(int, input().split())
		m = min(a * x + b, a * y + c)
		print(P // m)
except:
	pass


for _ in range(int(input())):
	(money, a, b, c, x, y) = map(int, input().split())
	anarcost = a * x + b
	chakricost = a * y + c
	ans = 0
	if anarcost < chakricost:
		ans += money // anarcost
		money -= anarcost * (money // anarcost)
		ans += money // chakricost
	else:
		ans += money // chakricost
		money -= chakricost * (money // chakricost)
		ans += money // anarcost
	print(ans)


def check(p, f, a, c, x, y):
	cost_a = a + x * f
	cost_c = c + f * y
	data_a = p // cost_a
	if cost_a >= cost_c:
		data_c = p // cost_c
		p = p - data_c * cost_c
		data_a = p // cost_a
	else:
		data_a = p // cost_a
		p = p - data_a * cost_a
		data_c = p // cost_c
	final = data_a + data_c
	return final
t = int(input())
for _ in range(t):
	(p, f, a, c, x, y) = map(int, input().split())
	print(check(p, f, a, c, x, y))


for _ in range(int(input())):
	(n, a, b, c, x, y) = map(int, input().split())
	p = min(x * a + b, y * a + c)
	print(n // p)


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	t1 = a * x + b
	t2 = a * y + c
	print(p // min(t1, t2))


T = int(input())
while T != 0:
	(p, a, b, c, x, y) = map(int, input().split())
	minimum = min(b + x * a, c + y * a)
	print(p // minimum)
	T -= 1


for _ in range(int(input())):
	(p, a, b, c, x, y) = map(int, input().split())
	an = b + x * a
	cn = c + y * a
	re = min(an, cn)
	print(p // re)