You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course.

You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ units.

In the blacksmith shop, you found $cnt_s$ swords and $cnt_w$ war axes. Each sword weights $s$ units and each war axe — $w$ units. You don't care what to take, since each of them will melt into one steel ingot.

What is the maximum number of weapons (both swords and war axes) you and your follower can carry out from the shop?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains two integers $p$ and $f$ ($1 \le p, f \le 10^9$) — yours and your follower's capacities.

The second line of each test case contains two integers $cnt_s$ and $cnt_w$ ($1 \le cnt_s, cnt_w \le 2 \cdot 10^5$) — the number of swords and war axes in the shop.

The third line of each test case contains two integers $s$ and $w$ ($1 \le s, w \le 10^9$) — the weights of each sword and each war axe.

It's guaranteed that the total number of swords and the total number of war axes in all test cases don't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print the maximum number of weapons (both swords and war axes) you and your follower can carry.


-----Example-----
Input
3
33 27
6 10
5 6
100 200
10 10
5 5
1 19
1 3
19 5

Output
11
20
3



-----Note-----

In the first test case:   you should take $3$ swords and $3$ war axes: $3 \cdot 5 + 3 \cdot 6 = 33 \le 33$  and your follower — $3$ swords and $2$ war axes: $3 \cdot 5 + 2 \cdot 6 = 27 \le 27$.  $3 + 3 + 3 + 2 = 11$ weapons in total.

In the second test case, you can take all available weapons even without your follower's help, since $5 \cdot 10 + 5 \cdot 10 \le 100$.

In the third test case, you can't take anything, but your follower can take $3$ war axes: $3 \cdot 5 \le 19$.

Difficulty: MEDIUM_HARD
Tags: Complete search

Mathematics

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(ca, cb) = map(int, input().split())
	(na, nb) = map(int, input().split())
	(wa, wb) = map(int, input().split())
	if wa > wb:
		(wa, wb) = (wb, wa)
		(na, nb) = (nb, na)
	limit = ca // wa

	def cal(x):
		res = x
		cur_a = ca - x * wa
		y = min(cb // wa, na - x)
		res = res + y
		cur_b = cb - y * wa
		p = min(cur_a // wb, nb)
		res += p
		q = min(cur_b // wb, nb - p)
		res += q
		return res
	out = 0
	for j in range(min(limit, na), -1, -1):
		ans = cal(j)
		if ans > out:
			out = ans
	for i in range(1000):
		aaaaaaa = 1
	print(out)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(w, s) = (s, w)
		(cs, cw) = (cw, cs)
	ans = min(p // w + f // w, cw)
	for i in range(cs):
		a = min(i + 1, p // s)
		b = min(cs - a, f // s)
		A = min((p - a * s) // w, cw)
		B = min((f - b * s) // w, cw - A)
		ans = max(ans, a + b + A + B)
		a = min(i + 1, f // s)
		b = min(cs - a, p // s)
		A = min((f - a * s) // w, cw)
		B = min((p - b * s) // w, cw - A)
		ans = max(ans, a + b + A + B)
	print(ans)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(cap1, cap2) = map(int, input().split())
	(ns, na) = map(int, input().split())
	(sweight, aweight) = map(int, input().split())
	if aweight < sweight:
		(aweight, sweight) = (sweight, aweight)
		(ns, na) = (na, ns)
	ans = 0
	for keep in range(ns + 1):
		if keep * sweight > cap1:
			continue
		hiskeep = min(ns - keep, cap2 // sweight)
		myleft = cap1 - keep * sweight
		hisleft = cap2 - hiskeep * sweight
		myaxe = min(myleft // aweight, na)
		hisaxe = min(hisleft // aweight, na - myaxe)
		ans = max(ans, hiskeep + keep + myaxe + hisaxe)
	print(ans)


t = int(input())
for i in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	maxi = 0
	for j in range(min(cs, p // s) + 1):
		k = min((p - s * j) // w, cw)
		xcs = cs - j
		xcw = cw - k
		if s > w:
			if w * xcw >= f:
				m = f // w
				l = 0
			else:
				m = xcw
				l = min((f - m * w) // s, xcs)
		elif s * xcs >= f:
			l = f // s
			m = 0
		else:
			l = xcs
			m = min((f - s * l) // w, xcw)
		maxi = max(maxi, l + m + j + k)
	print(maxi)


import math
for t in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	ans = 0
	if e > f:
		t = e
		e = f
		f = t
		t1 = c
		c = d
		d = t1
	for i in range(min(c, a // e) + 1):
		w1 = min(d, (a - i * e) // f)
		s2 = min(c - i, b // e)
		w2 = min(d - w1, (b - s2 * e) // f)
		ans = max(ans, i + s2 + w1 + w2)
	print(ans)


t = int(input())
for case in range(t):
	(p, f) = map(int, input().split())
	(swords, axes) = map(int, input().split())
	(s, w) = map(int, input().split())
	capacity = p + f
	if s <= w:
		if p // s + f // s <= swords:
			print(p // s + f // s)
		else:
			maxWeapons = 0
			for i in range(max(0, swords - f // s), min(p // s + 1, swords + 1)):
				weapons = 0
				if (p - i * s) // w + (f - (swords - i) * s) // w <= axes:
					weapons = (p - i * s) // w + (f - (swords - i) * s) // w + swords
				else:
					weapons = swords + axes
				if weapons > maxWeapons:
					maxWeapons = weapons
			print(maxWeapons)
	elif p // w + f // w <= axes:
		print(p // w + f // w)
	else:
		maxWeapons = 0
		for i in range(max(0, axes - f // w), min(p // w + 1, axes + 1)):
			weapons = 0
			if (p - i * w) // s + (f - (axes - i) * w) // s <= swords:
				weapons = (p - i * w) // s + (f - (axes - i) * w) // s + axes
			else:
				weapons = swords + axes
			if weapons > maxWeapons:
				maxWeapons = weapons
		print(maxWeapons)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	maxa = 0
	for c in range(min(cs, p // s) + 1):
		d = min((p - c * s) // w, cw)
		a = min(cs - c, f // s)
		b = min(cw - d, (f - a * s) // w)
		maxa = max(maxa, a + b + c + d)
	for c in range(min(cs, f // s) + 1):
		d = min((f - c * s) // w, cw)
		a = min(cs - c, p // s)
		b = min(cw - d, (p - a * s) // w)
		maxa = max(maxa, a + b + c + d)
	print(maxa)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

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

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(p, f) = neo()
	(cs, cw) = neo()
	(s, w) = neo()
	(p, f, Ans) = (max(p, f), min(p, f), 0)
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for i in range(cs + 1):
		t = 0
		if p - i * s >= 0:
			t += i + min((p - i * s) // w, cw)
			a = max(0, cs - i)
			q = min(a, f // s)
			t += q
			t += min(cw, (f - q * s) // w)
			Ans = max(Ans, t)
		else:
			break
	print(min(Ans, cs + cw))


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		temp = cnts
		cnts = cntw
		cntw = temp
		temp = s
		s = w
		w = temp
	mc = 0
	count = 0
	k = min(cnts, p // s)
	for i in range(0, k + 1):
		w1 = min(cntw, (p - i * s) // w)
		s2 = min(cnts - i, f // s)
		w2 = min(cntw - w1, (f - s2 * s) // w)
		count += i + w1 + s2 + w2
		if count > mc:
			mc = count
		count = 0
	print(mc)


t = int(input())
for _ in range(t):
	(p, f) = [int(x) for x in input().split()]
	(cs, cw) = [int(x) for x in input().split()]
	(s, w) = [int(x) for x in input().split()]
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	best = 0
	for i in range(cs + 1):
		if s * i <= p:
			war_me = min((p - s * i) // w, cw)
			tb = i + war_me
			sword_him = min(cs - i, f // s)
			tb += sword_him
			war_him = min((f - s * sword_him) // w, cw - war_me)
			tb += war_him
			best = max(best, tb)
	print(best)


t = int(input())
for i in range(t):
	(wa, wb) = map(int, input().split())
	(cs, ca) = map(int, input().split())
	(sword, axe) = map(int, input().split())
	if sword > axe:
		(sword, axe) = (axe, sword)
		(cs, ca) = (ca, cs)
	ans = 0
	for j in range(cs + 1):
		x = wa
		y = wb
		a = sword
		b = axe
		cnt = cs
		d = ca
		temp = 0
		if x - j * a >= 0:
			x -= j * a
			cnt -= j
			temp += j
			count = min(y // a, cnt)
			temp += count
			y -= min(cnt * a, y // a * a)
			cnt -= count
		else:
			break
		temp += x // b
		d -= x // b
		temp += min(y // b, d)
		ans = max(ans, temp)
	print(ans)


t = int(input())
for e in range(t):
	(p, f) = map(int, input().split())
	(ns, nw) = map(int, input().split())
	(ps, pw) = map(int, input().split())
	if ps > pw:
		(ps, pw) = (pw, ps)
		(ns, nw) = (nw, ns)
	best = -1
	for ns1 in range(0, min(ns, p // ps) + 1):
		nw1 = (p - ns1 * ps) // pw
		ns2 = min(ns - ns1, f // ps)
		nw2 = min(nw - nw1, (f - ns2 * ps) // pw)
		armes = ns1 + nw1 + ns2 + nw2
		if armes > best:
			best = armes
	print(best)


from sys import stdin
for _ in ' ' * int(stdin.readline()):
	(c1, c2) = map(int, stdin.readline().split())
	(cnt1, cnt2) = map(int, stdin.readline().split())
	(w1, w2) = map(int, stdin.readline().split())
	ans = 0
	for i in range(cnt1 + 1):
		(a1, b1, s) = (c1, c2, 0)
		k = min(a1 // w1, i)
		s += k
		a1 -= k * w1
		k = min(b1 // w1, cnt1 - k)
		b1 -= k * w1
		s += k
		k = min(a1 // w2, cnt2)
		s += k
		k = min(b1 // w2, cnt2 - k)
		s += k
		ans = max(ans, s)
	(cnt1, cnt2) = (cnt2, cnt1)
	(w1, w2) = (w2, w1)
	for i in range(cnt1 + 1):
		(a1, b1, s) = (c1, c2, 0)
		k = min(a1 // w1, i)
		s += k
		a1 -= k * w1
		k = min(b1 // w1, cnt1 - k)
		b1 -= k * w1
		s += k
		k = min(a1 // w2, cnt2)
		s += k
		k = min(b1 // w2, cnt2 - k)
		s += k
		ans = max(ans, s)
	print(ans)


import sys, heapq as h
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	(P, F) = getInts()
	(cnts, cntw) = getInts()
	(S, W) = getInts()
	if S > W:
		(S, W) = (W, S)
		(cnts, cntw) = (cntw, cnts)
	max_swords = min(cnts, P // S)
	best = 0
	for j in range(max_swords + 1):
		tmp_P = P - j * S
		tmp_cnts = cnts - j
		max_axe = min(tmp_P // W, cntw)
		tmp_cntw = cntw - max_axe
		max_swords_F = min(F // S, tmp_cnts)
		tmp_F = F - max_swords_F * S
		max_axe_F = min(tmp_F // W, tmp_cntw)
		best = max(best, j + max_axe + max_swords_F + max_axe_F)
	return best
for _ in range(getInt()):
	print(solve())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(ps, pw) = map(int, input().split())
	if pw > ps:
		(ps, pw) = (pw, ps)
		(cs, cw) = (cw, cs)
	ans = 0
	mx = 0
	for i in range(cs + 1):
		if i * ps > n:
			break
		a = i + min(cw, (n - i * ps) // pw)
		ncs = cs - i
		ncw = cw - min(cw, (n - i * ps) // pw)
		a += min(ncw, k // pw)
		a += min(ncs, (k - min(ncw, k // pw) * pw) // ps)
		ans = max(a, ans)
	print(ans)


t = int(input())
for i in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	num = 0
	ms = p // s
	for i in range(min(ms, cs) + 1):
		cnt = i
		rem = p - i * s
		cnt += rem // w
		rs = cs - i
		sm = f // s
		cnt += min(rs, sm)
		rp = f - min(rs, sm) * s
		rw = cw - rem // w
		sm1 = rp // w
		cnt += min(sm1, rw)
		num = max(num, cnt)
	print(num)


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(p, q) = map(int, input().split())
	(n, m) = map(int, input().split())
	(w, v) = map(int, input().split())
	if w > v:
		(w, v) = (v, w)
		(n, m) = (m, n)
	R = 0
	for c in range(n + 1):
		if p < c * w:
			break
		pp = p - c * w
		if q >= (n - c) * w:
			qq = q - (n - c) * w
			r = min(pp // v + qq // v, m) + n
		else:
			(r, qq) = divmod(q, w)
			r = r + min(pp // v, m) + c
		R = max(R, r)
	print(R)


from collections import defaultdict as dc
import sys
from collections import Counter as cnt
from collections import deque as dq
from copy import copy, deepcopy
import itertools
import math
mod = 10 ** 9 + 7

def sinp():
	p = str(sys.stdin.readline())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		for j in range(2 * i, n + 1, i):
			p[i] = 1
	return p

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

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def ind(a):
	return ord(a) - ord('A')

def digit(n):
	p = [int(i) for i in str(n)]
	return p

def check(p, n):
	l = str(p)
	s = ''
	for i in range(n):
		s = s + bin(int(l[i]))[2:]
	s = s[:-n]
	if s == '':
		return 0
	return int(s, 2)

def createcomb(a, n, i):
	if i == n:
		ans.append(a)
	else:
		for z in range(n):
			a.append(a[z])
			createcomb(a, n, z)
			a.pop()

def solve(a, n, a1, b1, c1):
	l = []
	r = []
	x = 0
	for i in range(n):
		if a[i] >= x:
			l.append(i)
			x = a[i]
	x = 0
	for i in range(n - 1, -1, -1):
		if a[i] >= x:
			r.append(i)
			x = a[i]
	z = cnt(r)
	c = 0
	p = len(l)
	q = len(r)
	for i in l:
		if z[i]:
			c += 1
	if p == a1 and q == b1 and (c1 == c):
		return 1
	return 0

def xor(a, b):
	s = ''
	for i in range(len(a)):
		if a[i] == '1' and b[i] == '0':
			s += '1'
		elif b[i] == '1' and a[i] == '0':
			s += '1'
		else:
			s += '0'
	return s
for t in range(inp()):
	(p, f) = line()
	(cnts, cntw) = line()
	(s, w) = line()
	ans = 0
	l = 0

	def extra(s, w, cnts, cntw, f):
		if s > w:
			return extra(w, s, cntw, cnts, f)
		if s * cnts >= f:
			return f // s
		return cnts + min((f - s * cnts) // w, cntw)
	for x in range(0, cnts + 1):
		y1 = max(0, p - x * s)
		z = min(y1 // w, cntw)
		if x * s + w * z <= p:
			ans = max(ans, x + z + extra(s, w, cnts - x, cntw - z, f))
	print(ans)


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	(p, f) = rl()
	(cnt_s, cnt_w) = rl()
	(s, w) = rl()
	ans = 0
	if s > w:
		temp = s
		s = w
		w = temp
		temp = cnt_s
		cnt_s = cnt_w
		cnt_w = temp
	for s1 in range(min(p // s + 1, cnt_s + 1)):
		w1 = min(cnt_w, (p - s * s1) // w)
		s2 = min(cnt_s - s1, f // s)
		w2 = min(cnt_w - w1, (f - s * s2) // w)
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)


for _ in range(int(input())):
	(p, f) = [int(i) for i in input().split()]
	(cnts, cntw) = [int(i) for i in input().split()]
	(s, w) = [int(i) for i in input().split()]
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	s1 = 0
	w1 = min(cntw, (p - s1 * s) // w)
	s2 = min(cnts - s1, f // s)
	w2 = min(cntw - w1, (f - s2 * s) // w)
	count = s1 + s2 + w1 + w2
	for s1 in range(1, min(cnts, p // s) + 1):
		w1 = min(cntw, (p - s1 * s) // w)
		s2 = min(cnts - s1, f // s)
		w2 = min(cntw - w1, (f - s2 * s) // w)
		count = max(count, s1 + s2 + w1 + w2)
	print(count)


t = int(input().split()[0])
for i in range(t):
	[p, f] = [int(x) for x in input().split()]
	[cs, ca] = [int(x) for x in input().split()]
	[s, a] = [int(x) for x in input().split()]
	if s > a:
		[s, a] = [a, s]
		[cs, ca] = [ca, cs]
	best = 0
	for p_ns in range(0, min(cs, p // s) + 1):
		p_na = (p - p_ns * s) // a
		p_na = min(p_na, ca)
		res = p_ns + p_na
		rest_s = cs - p_ns
		rest_a = ca - p_na
		f_ns = min(rest_s, f // s)
		space_f = f - f_ns * s
		f_na = min(rest_a, space_f // a)
		res += f_ns + f_na
		best = max(best, res)
	print(best)


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prdbg(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
	pass

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(p, f) = rint()
	(cnts, cntw) = rint()
	(s, w) = rint()
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	maxwn = 0
	for i in range(cnts + 1):
		cntsp = i
		pp = p
		if pp // s < cntsp:
			cntsp = pp // s
		wn = cntsp
		pp -= cntsp * s
		cntwp = pp // w
		if cntwp > cntw:
			cntwp = cntw
		wn += cntwp
		pp -= cntwp * w
		ff = f
		cntsf = ff // s
		if cntsf > cnts - cntsp:
			cntsf = cnts - cntsp
		wn += cntsf
		ff -= cntsf * s
		cntwf = ff // w
		if cntwf > cntw - cntwp:
			cntwf = cntw - cntwp
		wn += cntwf
		maxwn = max(maxwn, wn)
	print(maxwn)


mod = 10 ** 9 + 7

def solve():
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(w, s) = (s, w)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		pp = p
		ff = f
		tcs = cs
		tcw = cw
		ps = min(i, pp // s)
		tcs -= ps
		pw = min(tcw, (pp - ps * s) // w)
		tcw -= pw
		fs = min(tcs, ff // s)
		fw = min(tcw, (ff - s * fs) // w)
		ans = max(ans, ps + pw + fs + fw)
	print(ans)
t = int(input())
while t > 0:
	solve()
	t -= 1


from sys import stdin, stdout
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(s, x) = map(int, input().split())
	(sw, xw) = map(int, input().split())
	if xw < sw:
		(sw, xw) = (xw, sw)
		(s, x) = (x, s)
	ans = 0
	for i in range(s + 1):
		temp = 0
		f1 = f
		p1 = p
		s1 = s
		x1 = x
		if i * sw <= p1:
			temp += i
			p1 -= i * sw
			s1 -= i
		c = min(p1 // xw, x1)
		x1 -= c
		temp += c
		c = min(f1 // sw, s1)
		f1 -= c * sw
		temp += c
		temp += min(f1 // xw, x1)
		ans = max(ans, temp)
	print(ans)


t = int(input())
while t:
	(p, f) = list(map(int, input().split()))
	(cs, ca) = list(map(int, input().split()))
	(ws, wa) = list(map(int, input().split()))
	if ws > wa:
		(cs, ca) = (ca, cs)
		(ws, wa) = (wa, ws)
	ans = 0
	for i in range(cs + 1):
		if i * ws <= p:
			myLeft = p - i * ws
			keep = min(cs - i, f // ws)
			hisLeft = f - keep * ws
			myAks = min(myLeft // wa, ca)
			hisAks = min(hisLeft // wa, ca - myAks)
			ans = max(ans, i + keep + myAks + hisAks)
		else:
			break
	print(ans)
	t -= 1


for i in range(int(input())):
	(mca, mcb) = list(map(int, input().split()))
	(cs, ca) = list(map(int, input().split()))
	(ws, wa) = list(map(int, input().split()))
	if ws > wa:
		temp = wa
		temp1 = ws
		temp2 = cs
		temp3 = ca
		ws = temp
		wa = temp1
		cs = temp3
		ca = temp2
	ans = 0
	for i in range(cs + 1):
		if ws * i > mca:
			continue
		temp0 = min(cs - i, mcb // ws)
		myl = mca - i * ws
		myr = mcb - temp0 * ws
		temp1 = min(myl // wa, ca)
		temp2 = min(myr // wa, ca - temp1)
		ans = max(ans, i + temp0 + temp1 + temp2)
	print(round(ans))


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(ns, nw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(ns, nw) = (nw, ns)
	if p > f:
		(p, f) = (f, p)
	best = 0
	for i in range(min(ns, p // s) + 1):
		cur1s = i
		cur1w = min(nw, (p - cur1s * s) // w)
		cur2s = min(f // s, ns - i)
		cur2w = min(nw - cur1w, (f - min(f // s, ns - i) * s) // w)
		cur = cur1s + cur2s + cur1w + cur2w
		if cur > best:
			best = cur
	print(best)


for t in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	res = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for ns1 in range(cs + 1):
		if ns1 * s > p:
			continue
		ns2 = min(cs - ns1, f // s)
		nw1 = min((p - ns1 * s) // w, cw)
		nw2 = min((f - ns2 * s) // w, cw - nw1)
		res = max(res, ns1 + ns2 + nw1 + nw2)
	print(res)


num = int(input())
output = []
for i in range(num):
	(p, f) = map(int, input().split())
	(n, m) = map(int, input().split())
	(s, w) = map(int, input().split())
	max_num = 0
	r_all = (n, p // s, m, p // w)
	r_min = r_all.index(min(r_all))
	t = 1 if r_min < 2 else 0
	for i in range(r_all[r_min] + 1):
		if t:
			j = min((p - i * s) // w, m)
			nums = [i, j]
		else:
			j = min((p - i * w) // s, n)
			nums = [j, i]
		if s < w:
			if (n - nums[0]) * s > f:
				nums.extend([f // s, 0])
			else:
				nums.extend([n - nums[0], min((f - (n - nums[0]) * s) // w, m - nums[1])])
		elif (m - nums[1]) * w > f:
			nums.extend([f // w, 0])
		else:
			nums.extend([m - nums[1], min((f - (m - nums[1]) * w) // s, n - nums[0])])
		if sum(nums) > max_num:
			max_num = sum(nums)
	output.append(max_num)
for i in output:
	print(i)


t = int(input())
i = 0
while i < t:
	pf = list(map(int, input().split()))
	Q = list(map(int, input().split()))
	sw = list(map(int, input().split()))
	p = pf[0]
	f = pf[1]
	if sw[0] <= sw[1]:
		Qs = Q[0]
		Qw = Q[1]
	else:
		Qs = Q[1]
		Qw = Q[0]
	s = min(sw)
	w = max(sw)
	answer = 0
	j = 0
	while j <= min(Qs, p // s):
		s1 = j
		w1 = min(Qw, (p - s1 * s) // w)
		s2 = min(Qs - s1, f // s)
		w2 = min(Qw - w1, (f - s2 * s) // w)
		answer = max(answer, s1 + s2 + w1 + w2)
		j += 1
	print(answer)
	i += 1


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

def list_input():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(p, f) = multiple_input()
	(cs, cw) = multiple_input()
	(s, w) = multiple_input()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	(s1, s2, w1, w2) = (0, 0, 0, 0)
	i = 0
	end = min(cs, p // s)
	m = 0
	while i <= end:
		s1 = i
		w1 = min(cw, (p - s1 * s) // w)
		s2 = min(cs - s1, f // s)
		w2 = min(cw - w1, (f - s2 * s) // w)
		m = max(m, s1 + s2 + w1 + w2)
		i += 1
	print(m)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(sn, an) = map(int, input().split())
	(s, a) = map(int, input().split())
	if a < s:
		(s, a) = (a, s)
		(sn, an) = (an, sn)
	i = 0
	ans = 0
	while i <= sn and i * s <= p:
		x = sn - i
		y = an
		t = p - i * s
		temp_ans = i
		if y * a < t:
			temp_ans += y
			y = 0
		else:
			xx = t // a
			temp_ans += xx
			y -= xx
		t = f
		if x * s < t:
			t -= x * s
			temp_ans += x
			x = 0
			if y * a < t:
				temp_ans += y
				t -= y * a
				y = 0
			else:
				xx = t // a
				temp_ans += xx
			ans = max(ans, temp_ans)
		else:
			xx = t // s
			temp_ans += xx
			ans = max(ans, temp_ans)
		i += 1
	print(ans)


import os
from sys import stdin, stdout

def solve(tc):
	(p, f) = map(int, stdin.readline().split())
	(cs, cw) = map(int, stdin.readline().split())
	(s, w) = map(int, stdin.readline().split())
	ans = 0
	total = p + f
	for i in range(cs + 1):
		prem = p - i * s
		if prem < 0:
			break
		frem = 0
		j = cs - i
		if f >= j * s:
			frem = f - j * s
		else:
			j = f // s
			frem = f - j * s
		k = prem // w
		l = cw - k
		if frem < l * w:
			l = frem // w
		ans = max(ans, i + j + k + l)
	for i in range(cw + 1):
		prem = p - i * w
		if prem < 0:
			break
		frem = 0
		j = cw - i
		if f >= j * w:
			frem = f - j * w
		else:
			j = f // w
			frem = f - j * w
		k = prem // s
		l = cs - k
		if frem < l * s:
			l = frem // s
		ans = max(ans, i + j + k + l)
	print(ans)
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


def read_int():
	return int(input().strip())

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

def read_floats():
	return list(map(float, input().strip().split()))

def read_str():
	return input().strip()

def solve_t():
	(p, f) = read_ints()
	(cnt_s, cnt_w) = read_ints()
	(s, w) = read_ints()
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	ans = 0
	for ps in range(cnt_s + 1):
		if ps * s > p:
			break
		pw = min(cnt_w, (p - ps * s) // w)
		fs = min(cnt_s - ps, f // s)
		fw = min(cnt_w - pw, (f - fs * s) // w)
		ans = max(ans, ps + pw + fs + fw)
	print(ans)

def solve():
	t = read_int()
	for _ in range(t):
		solve_t()
solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(p, f) = list(map(int, input().split()))
	(cw, ca) = list(map(int, input().split()))
	(ww, wa) = list(map(int, input().split()))
	if ww > wa:
		(ww, wa) = (wa, ww)
		(cw, ca) = (ca, cw)
	if p // ww + f // ww < cw:
		ans = p // ww + f // ww
	else:
		ans = cw
		best = 0
		for i in range(cw + 1):
			x = i
			y = cw - i
			tmp_a = p - x * ww
			tmp_b = f - y * ww
			if tmp_a > -1 and tmp_b > -1:
				tempp = tmp_a // wa + tmp_b // wa
				tempp = min(tempp, ca)
				best = max(best, tempp)
		ans += best
	print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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 ik in range(int(input())):
	(n, k) = map(int, input().split())
	(ca, cw) = map(int, input().split())
	(s, w1) = map(int, input().split())
	if s > w1:
		(s, w1) = (w1, s)
		(ca, cw) = (cw, ca)
	tot = 0
	lwe = [n, k, ca, cw, s, w1]
	for i in range(ca + 1):
		ans = 0
		(n, k, ca, cw, s, w1) = (lwe[0], lwe[1], lwe[2], lwe[3], lwe[4], lwe[5])
		w = n // s
		if w < i:
			continue
		ans += i
		n -= i * s
		ans += min(cw, n // w1)
		cw -= min(cw, n // w1)
		ca -= i
		ans += min(ca, k // s)
		k -= min(ca, k // s) * s
		ans += min(cw, k // w1)
		tot = max(tot, ans)
	print(tot)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cn, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(cn, cw) = (cw, cn)
		(s, w) = (w, s)
	if f > p:
		(f, p) = (p, f)
	w1 = 0
	w2 = 0
	s2 = 0
	ans = 0
	for i in range(min(cn, p // s) + 1):
		w1 = min(cw, (p - i * s) // w)
		s2 = min(cn - i, f // s)
		w2 = min(cw - w1, (f - s2 * s) // w)
		ans = max(s2 + w1 + w2 + i, ans)
	print(ans)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(p, f) = mi()
	(cs, cw) = mi()
	(s, w) = mi()
	ans = 0
	if w > s:
		(s, w, cs, cw) = (w, s, cw, cs)
	(r, g) = (f, p)
	(xx, yy) = (w, s)
	for i in range(cw + 1):
		(f, p) = (r, g)
		(w, s) = (xx, yy)
		f -= i * w
		if f < 0:
			break
		c = i
		(acw, acs) = (cw - i, cs)
		if p // w > acw:
			p -= acw * w
			c += acw
			acw = 0
		else:
			c += p // w
			p %= w
			acw = 0
		(w, acw) = (s, cs)
		if f // w <= acw:
			c += f // w
			acw -= f // w
			f %= w
		else:
			c += acw
			f -= w * acw
			acw = 0
		if p // w <= acw:
			c += p // w
			acw -= p // w
			p %= w
		else:
			c += acw
			p -= w * acw
			acw = 0
		ans = max(ans, c)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	best = 0
	for i in range(cs + 1):
		if i * s <= p:
			axes = min(cw, (p - i * s) // w)
			rest_sw = min(cs - i, f // s)
			rest_axes = min(cw - axes, (f - rest_sw * s) // w)
			tot = i + axes + rest_sw + rest_axes
			best = max(best, tot)
	print(best)


for t in range(int(input())):
	(p, f) = list(map(int, input().split()))
	(c_sw, c_ax) = list(map(int, input().split()))
	(w_sw, w_ax) = list(map(int, input().split()))
	if w_sw > w_ax:
		(c_sw, c_ax) = (c_ax, c_sw)
		(w_sw, w_ax) = (w_ax, w_sw)
	ans = 0
	for n_sw_p in range(c_sw + 1):
		n_sw_f = c_sw - n_sw_p
		n_sw_p = min(n_sw_p, p // w_sw)
		n_sw_f = min(n_sw_f, f // w_sw)
		n_ax_p = (p - n_sw_p * w_sw) // w_ax
		n_ax_f = (f - n_sw_f * w_sw) // w_ax
		n_ax = min(n_ax_p + n_ax_f, c_ax)
		ans = max(ans, n_sw_p + n_sw_f + n_ax)
	print(ans)


t = int(input())
for i in range(t):
	(p, f) = map(int, input().rstrip().split())
	(c_s, c_w) = map(int, input().rstrip().split())
	(s, w) = map(int, input().rstrip().split())
	if s > w:
		t = s
		s = w
		w = t
		temp = c_s
		c_s = c_w
		c_w = temp
	res = 0
	for s1 in range(0, min(c_s, p // s) + 1):
		w1 = min(c_w, (p - s1 * s) // w)
		s2 = min(c_s - s1, f // s)
		w2 = min(c_w - w1, (f - s2 * s) // w)
		res = max(res, s1 + s2 + w1 + w2)
	print(res)


t = int(input())
for i in range(0, t):
	(p, q) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		temp = s
		s = w
		w = temp
		temp = cs
		cs = cw
		cw = temp
	ans = 0
	for px in range(0, min(cs, int(p / s)) + 1):
		py = min(cw, int((p - s * px) / w))
		qx = min(cs - px, int(q / s))
		qy = min(cw - py, int((q - s * qx) / w))
		ans = max(ans, px + py + qx + qy)
	print(ans)


tn = int(input())
for ti in range(tn):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s < w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for ps in range(cs + 1):
		if ps * s > p:
			break
		pw = min((p - ps * s) // w, cw)
		fw = min(f // w, cw - pw)
		fs = min((f - fw * w) // s, cs - ps)
		ans = max(ans, ps + pw + fs + fw)
	print(ans)


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	(p, f) = list(map(int, sys.stdin.readline().strip().split()))
	(ns, nw) = list(map(int, sys.stdin.readline().strip().split()))
	(s, w) = list(map(int, sys.stdin.readline().strip().split()))
	if s > w:
		(s, w) = (w, s)
		(ns, nw) = (nw, ns)
	ans = 0
	for ps in range(0, ns + 1):
		if ps * s <= p:
			pw = min(nw, (p - ps * s) // w)
			fs = min(ns - ps, f // s)
			fw = min((f - fs * s) // w, nw - pw)
			ans = max(ans, ps + pw + fs + fw)
	print(ans)


for idf in range(int(input())):
	(p, f) = map(int, input().split())
	(n, m) = map(int, input().split())
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
		(n, m) = (m, n)
	a1 = min(n, p // a)
	t = 0
	for i in range(a1 + 1):
		b1 = min(m, (p - i * a) // b)
		a2 = min(n - i, f // a)
		b2 = min(m - b1, (f - a2 * a) // b)
		t = max(t, i + a2 + b1 + b2)
	print(t)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

def IO():
	return stdin.readline()

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	(p, f) = IP()
	(c1, c2) = IP()
	(w1, w2) = IP()
	if w1 > w2:
		(w1, w2) = (w2, w1)
		(c1, c2) = (c2, c1)
	ans = -1000000000.0
	for i in range(c1 + 1):
		if p - i * w1 >= 0:
			a2 = min(c2, (p - i * w1) // w2)
			a3 = min(c1 - i, f // w1)
			a4 = min(c2 - a2, (f - a3 * w1) // w2)
			ans = max(ans, i + a2 + a3 + a4)
	print(ans)
	return
t = II()
for i in range(t):
	solve()


def get_results():
	(cap1, cap2) = list(map(int, input().split()))
	(n1, n2) = list(map(int, input().split()))
	(w1, w2) = list(map(int, input().split()))
	max_w = 0
	if w2 < w1:
		(n1, n2) = (n2, n1)
		(w1, w2) = (w2, w1)
	for your_lighter in range(0, min(n1, cap1 // w1) + 1):
		your_heavier = min(n2, (cap1 - your_lighter * w1) // w2)
		follower_lighter = min(n1 - your_lighter, cap2 // w1)
		follower_heavier = min(n2 - your_heavier, (cap2 - follower_lighter * w1) // w2)
		max_w = max(max_w, your_lighter + your_heavier + follower_lighter + follower_heavier)
	return max_w

def main():
	t = int(input())
	res = []
	for i in range(t):
		print(get_results())
main()


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	(p, f) = I()
	(cs, cw) = I()
	(s, w) = I()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	i = 0
	while i <= cs:
		if i * s > p:
			break
		p1 = i
		p2 = min((p - p1 * s) // w, cw)
		f1 = min(cs - i, f // s)
		f2 = min((f - f1 * s) // w, cw - p2)
		ans = max(ans, p1 + p2 + f1 + f2)
		i += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	temp = min(cnts, p // s)
	ans = 0
	for i in range(temp + 1):
		s1 = i
		w1 = min((p - s * i) // w, cntw)
		s2 = min(cnts - s1, f // s)
		w2 = min((f - s2 * s) // w, cntw - w1)
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(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
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	ans = 0
	(p, f) = mapin()
	(a, b) = mapin()
	(s, w) = mapin()
	i = 0
	if s < w:
		(w, s) = (s, w)
		(a, b) = (b, a)
	while i <= a and s * i <= p:
		aa = s * i
		aaa = i
		temp = p - aa
		temp = temp // w
		if temp > b:
			temp = b
		aaa += temp
		temp = b - temp
		temp2 = a - i
		temp3 = f // w
		if temp3 > temp:
			temp3 = temp
		temp4 = f - temp3 * w
		temp5 = temp4 // s
		if temp5 > temp2:
			temp5 = temp2
		aaa += temp3
		aaa += temp5
		i += 1
		ans = max(ans, aaa)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	(p, f) = (max(p, f), min(p, f))
	if w < s:
		(cnts, s, cntw, w) = (cntw, w, cnts, s)
	sNo = p // s + f // s
	sNo = min(sNo, cnts)
	best = sNo
	for i in range(sNo + 1):
		if p // s < i:
			break
		if f // s < sNo - i:
			continue
		remainingP = p - s * i
		remainingF = f - (sNo - i) * s
		additionalW = remainingP // w + remainingF // w
		additionalW = min(additionalW, cntw)
		best = max(best, sNo + additionalW)
	print(best)


import sys
(_ord, inp, num, neg, _Index) = (lambda x: x, [], 0, False, 0)
(i, s) = (0, sys.stdin.buffer.read())
try:
	while True:
		if s[i] >= b'0'[0]:
			num = 10 * num + _ord(s[i]) - 48
		elif s[i] == b'-'[0]:
			neg = True
		elif s[i] != b'\r'[0]:
			inp.append(-num if neg else num)
			(num, neg) = (0, False)
		i += 1
except IndexError:
	pass
if s and s[-1] >= b'0'[0]:
	inp.append(-num if neg else num)

def fin(size=None):
	global _Index
	if size == None:
		ni = _Index
		_Index += 1
		return inp[ni]
	else:
		ni = _Index
		_Index += size
		return inp[ni:ni + size]
_T_ = fin()
for _t_ in range(_T_):
	(p, f) = fin(2)
	(cs, cw) = fin(2)
	(s, w) = fin(2)
	if w < s:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(0, cs + 1):
		itakes = min(p // s, i)
		itakew = min(cw, (p - itakes * s) // w)
		ftakes = min(cs - itakes, f // s)
		ftakew = min(cw - itakew, (f - ftakes * s) // w)
		ans = max(ans, itakes + itakew + ftakes + ftakew)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		t = w
		w = s
		s = t
		t = cw
		cw = cs
		cs = t
	ans = 0
	for i in range(0, min(p // s, cs) + 1):
		s2 = min(f // s, cs - i)
		s3 = min(cw, (p - i * s) // w)
		s4 = min(cw - s3, (f - s2 * s) // w)
		ans = max(ans, i + s2 + s3 + s4)
	print(ans)


def func(cnts, cntw, s, w, p, f):
	if s < w:
		pass
	else:
		(cnts, cntw) = (cntw, cnts)
		(s, w) = (w, s)
	ans = 0
	for s1 in range(min(cnts, p // s) + 1):
		s2 = min(cntw, (p - s1 * s) // w)
		w1 = min(cnts - s1, f // s)
		w2 = min(cntw - s2, (f - w1 * s) // w)
		ans = max(ans, s1 + s2 + w1 + w2)
	return ans
t = int(input())
for k in range(t):
	j = [int(i) for i in input().split()]
	p = j[0]
	f = j[1]
	j = [int(i) for i in input().split()]
	cnts = j[0]
	cntw = j[1]
	j = [int(i) for i in input().split()]
	s = j[0]
	w = j[1]
	print(func(cnts, cntw, s, w, p, f))


for tt in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(w, s) = (s, w)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(0, cnts + 1):
		(pp, ff, cntss, cntww, ss, ww) = (p, f, cnts, cntw, s, w)
		this = 0
		takeS = min(i, pp // ss)
		cntss -= takeS
		pp -= takeS * ss
		takeW = min(cntww, pp // ww)
		cntww -= takeW
		pp -= takeW * ww
		this += takeS + takeW
		takeS = min(cntss, ff // ss)
		ff -= takeS * ss
		takeW = min(cntww, ff // ww)
		this += takeS + takeW
		ans = max(ans, this)
	print(ans)


def maxItem(p, f, cnts, cntw, s, w):
	if s > w:
		return maxItem(p, f, cntw, cnts, w, s)
	if p < f:
		return maxItem(f, p, cntw, cnts, w, s)
	ans = 0
	for s1 in range(min(cnts, p // s) + 1):
		w1 = min(cntw, (p - s1 * s) // w)
		s2 = min(cnts - s1, f // s)
		w2 = min(cntw - w1, (f - s2 * s) // w)
		ans = max(ans, s1 + s2 + w1 + w2)
	return ans
t = int(input())
for _ in range(t):
	(p, f) = [*map(int, input().split())][:2]
	(cnts, cntw) = [*map(int, input().split())][:2]
	(s, w) = [*map(int, input().split())][:2]
	print(maxItem(p, f, cnts, cntw, s, w))


import sys
from collections import namedtuple
Equipment = namedtuple('Equipment', ['count', 'weight'])

def solve(player_capacity, follower_capacity, swords, axes):
	soln = 0
	for player_swords in range(0, 1 + min(player_capacity // swords.weight, swords.count)):
		player_remaining_capacity = player_capacity - player_swords * swords.weight
		player_axes = min(player_remaining_capacity // axes.weight, axes.count)
		remaining_swords = swords.count - player_swords
		remaining_axes = axes.count - player_axes
		if swords.weight < axes.weight:
			follower_swords = min(follower_capacity // swords.weight, remaining_swords)
			follower_remaining_capacity = follower_capacity - follower_swords * swords.weight
			follower_axes = min(follower_remaining_capacity // axes.weight, remaining_axes)
		else:
			follower_axes = min(follower_capacity // axes.weight, remaining_axes)
			follower_remaining_capacity = follower_capacity - follower_axes * axes.weight
			follower_swords = min(follower_remaining_capacity // swords.weight, remaining_swords)
		soln = max(soln, player_swords + player_axes + follower_axes + follower_swords)
	return soln

def main():
	test_cases = int(sys.stdin.readline())
	for _ in range(test_cases):
		(player_capacity, follower_capacity) = (int(i) for i in sys.stdin.readline().split())
		(sword_count, axe_count) = (int(i) for i in sys.stdin.readline().split())
		(sword_weight, axe_weight) = (int(i) for i in sys.stdin.readline().split())
		(swords, axes) = (Equipment(sword_count, sword_weight), Equipment(axe_count, axe_weight))
		print(solve(player_capacity, follower_capacity, swords, axes))
main()


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(sc, wc) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(sc, wc) = (wc, sc)
	for i in range(min(sc, p // s) + 1):
		wp = min(wc, (p - i * s) // w)
		sf = min(sc - i, f // s)
		wf = min(wc - wp, (f - sf * s) // w)
		ans = max(ans, i + wp + sf + wf)
	print(ans)


t = int(input())
for qwe in range(t):
	(p, f1) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ansold = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	pc = p
	f1c = f1
	csc = cs
	cwc = cw
	sc = s
	wc = w
	for i in range(min(cs, p // s), -1, -1):
		myw = min((p - i * s) // w, cw)
		yous = min(cs - i, f1 // s)
		youw = min(cw - myw, (f1 - yous * s) // w)
		ans = i + myw + yous + youw
		if ans > ansold:
			ansold = ans
	print(ansold)


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(p, f) = R()
	a = R()
	b = R()
	((x, a), (y, b)) = sorted(zip(b, a))
	a = min(a, p // x + f // x) * x
	print(a // x + min(b, max(((p - u) // y + (f - a + u) // y for u in range(a - min(a, f - f % x), min(a, p) + 1, x)))))


import sys

def main():
	inp = [int(x) for x in sys.stdin.read().split()]
	ii = 0
	t = inp[ii]
	ii += 1
	for _ in range(t):
		p = inp[ii]
		ii += 1
		f = inp[ii]
		ii += 1
		cnts = inp[ii]
		ii += 1
		cntw = inp[ii]
		ii += 1
		s = inp[ii]
		ii += 1
		w = inp[ii]
		ii += 1
		best = 0
		for i in range(cnts + 1):
			counter = i
			rems = cnts - i
			pbal = p - i * s
			if pbal < 0:
				break
			wtake = min(pbal // w, cntw)
			counter += wtake
			remw = cntw - wtake
			if s <= w:
				stake = min(f // s, rems)
				fbal = f - stake * s
				counter += stake
				counter += min(fbal // w, remw)
			else:
				wtakef = min(f // w, remw)
				fbal = f - wtakef * w
				counter += wtakef
				counter += min(fbal // s, rems)
			best = max(best, counter)
		print(best)
main()


tc = int(input())
for _ in range(tc):
	(l1, l2) = [int(x) for x in input().strip().split()]
	(cnt1, cnt2) = [int(x) for x in input().strip().split()]
	(w1, w2) = [int(x) for x in input().strip().split()]
	diff = abs(w1 - w2)
	if w1 < w2:
		smallw = w1
		smallc = cnt1
		bigw = w2
		bigc = cnt2
	else:
		smallw = w2
		smallc = cnt2
		bigw = w1
		bigc = cnt1
	if l1 > l2:
		bigl = l1
		smalll = l2
	else:
		bigl = l2
		smalll = l1
	biggest = 0
	stop = False
	for i in range(bigl // smallw + 1):
		if stop:
			break
		fit = i
		tsmallc = smallc
		tbigc = bigc
		if fit > smallc:
			fit = smallc
			stop = True
		remain = bigl - fit * smallw
		fit2 = remain // bigw
		if fit2 > tbigc:
			fit2 = tbigc
		pick1 = fit
		pick2 = fit2
		tsmallc -= pick1
		tbigc -= pick2
		fit = smalll // smallw
		if fit > tsmallc:
			fit = tsmallc
		remain = smalll - fit * smallw
		fit2 = remain // bigw
		if fit2 > tbigc:
			fit2 = tbigc
		total = pick1 + pick2 + fit + fit2
		if total > biggest:
			biggest = total
	print(biggest)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for a1 in range(cs + 1):
		if a1 * s > p:
			break
		a2 = min(cs - a1, f // s)
		b1 = (p - a1 * s) // w
		b2 = min(cw - b1, (f - a2 * s) // w)
		ans = max(ans, a1 + a2 + b1 + b2)
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		(p, f) = map(int, input().split())
		(ns, na) = map(int, input().split())
		(ws, wa) = map(int, input().split())
		if ws > wa:
			(ws, wa) = (wa, ws)
			(ns, na) = (na, ns)
		ans = -1
		for i in range(ns + 1):
			sp = i
			if p < sp * ws:
				break
			sf = min(ns - sp, f // ws)
			ap = min((p - sp * ws) // wa, na)
			af = min(na - ap, (f - ws * sf) // wa)
			ans = max(ans, sp + ap + sf + af)
		(p, f) = (f, p)
		for i in range(ns + 1):
			sp = i
			if p < sp * ws:
				break
			sf = min(ns - sp, f // ws)
			ap = min((p - sp * ws) // wa, na)
			af = min(na - ap, (f - ws * sf) // wa)
			ans = max(ans, sp + ap + sf + af)
		print(ans)
	return
main()


import os
import sys
from io import BytesIO, IOBase

def main():
	for t in range(int(input())):
		(p, f) = map(int, input().split())
		(cs, cw) = map(int, input().split())
		(s, w) = map(int, input().split())
		if s == w:
			print(min(cs + cw, p // s + f // s))
		elif s < w:
			if p // s + f // s <= cs:
				print(p // s + f // s)
			else:
				x = min(p // s * s, cs * s)
				y = cs * s - x
				ma = 0
				while x >= 0 and y <= f:
					ma = max(ma, min((p - x) // w + (f - y) // w, cw))
					x = x - s
					y = y + s
				print(ma + cs)
		elif p // w + f // w <= cw:
			print(p // w + f // w)
		else:
			x = min(p // w * w, cw * w)
			y = cw * w - x
			ma = 0
			while x >= 0 and y <= f:
				ma = max(ma, min((p - x) // s + (f - y) // s, cs))
				x = x - w
				y = y + w
			print(ma + cw)
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')
main()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	(ca, cw) = map(int, input().split())
	(s, w1) = map(int, input().split())
	if s > w1:
		(s, w1) = (w1, s)
		(ca, cw) = (cw, ca)
	tot = 0
	lwe = [n, k, ca, cw, s, w1]
	for i in range(ca + 1):
		ans = 0
		(n, k, ca, cw, s, w1) = (lwe[0], lwe[1], lwe[2], lwe[3], lwe[4], lwe[5])
		w = n // s
		if w < i:
			continue
		ans += i
		n -= i * s
		ans += min(cw, n // w1)
		cw -= min(cw, n // w1)
		ca -= i
		ans += min(ca, k // s)
		k -= min(ca, k // s) * s
		ans += min(cw, k // w1)
		tot = max(tot, ans)
	print(tot)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(ns, nx) = map(int, input().split())
	(ws, wx) = map(int, input().split())
	ans = 0
	if wx < ws:
		(wx, ws) = (ws, wx)
		(ns, nx) = (nx, ns)
	if ws <= wx:
		ans = 0
		for i in range(ns + 1):
			ui = i
			uj = 0
			tmp = 0
			if p - i * ws >= 0:
				if (p - i * ws) // wx >= nx:
					tmp += nx
					uj = nx
				else:
					tmp += (p - i * ws) // wx
					uj = tmp
				tmp += i
			else:
				tmp += p // ws
				ui = tmp
			if f - (ns - ui) * ws >= 0:
				if (f - (ns - ui) * ws) // wx >= nx - uj:
					tmp += nx - uj
				else:
					tmp += (f - (ns - ui) * ws) // wx
				tmp += ns - ui
			else:
				tmp += f // ws
			ans = max(ans, tmp)
	print(ans)


t = int(input())
while t:
	t -= 1
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s < w:
		for s1 in range(min(p // s, cs) + 1):
			w1 = min((p - s1 * s) // w, cw)
			s2 = min(f // s, cs - s1)
			w2 = min((f - s2 * s) // w, cw - w1)
			ans = max(ans, s1 + s2 + w1 + w2)
	else:
		for w1 in range(min(p // w, cw) + 1):
			s1 = min((p - w1 * w) // s, cs)
			w2 = min(f // w, cw - w1)
			s2 = min((f - w2 * w) // s, cs - s1)
			ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)


def solve(mid):
	cs = min(mid, cnt_s)
	cw = mid - cs
	for i in range(cs + 1):
		nokori_p = p - i * s
		nokori_f = f - (cs - i) * s
		if nokori_p < 0 or nokori_f < 0:
			continue
		if nokori_p // w + nokori_f // w < cw:
			continue
		return True
	return False
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
		(s, w) = (w, s)
	ok = 0
	ng = cnt_s + cnt_w + 1
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if solve(mid):
			ok = mid
		else:
			ng = mid
	print(ok)


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

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

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(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
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve(c1, c2, maxi1, maxi2):
	for i in range(1, maxi1 + 1):
		if i not in c1:
			return False
	for i in range(1, maxi2 + 1):
		if i not in c2:
			return False
	return True

def main():
	for _ in range(iin()):
		(p, f) = ain()
		(a, b) = ain()
		(aw, bw) = ain()
		if aw > bw:
			(aw, bw) = (bw, aw)
			(a, b) = (b, a)
		x = min(a, p // aw)
		ans = 0
		for i in range(x + 1):
			w1 = min(b, (p - aw * i) // bw)
			s1 = min(a - i, f // aw)
			w2 = min(b - w1, (f - aw * s1) // bw)
			ans = max(ans, w1 + s1 + w2 + i)
		print(ans)
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re 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
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

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 or x == 0:
			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)
num = int(z())
for _ in range(num):
	(p, f) = zz()
	(cnts, cnta) = zz()
	(s, a) = zz()
	if s > a:
		(s, a) = (a, s)
		(cnts, cnta) = (cnta, cnts)
	best = 0
	for i in range(cnts + 1):
		if i * s <= p:
			axes = min(cnta, (p - i * s) // a)
			rest_sw = min(cnts - i, f // s)
			rest_axes = min(cnta - axes, (f - rest_sw * s) // a)
			total = i + axes + rest_sw + rest_axes
			best = max(best, total)
	print(best)


for _ in range(int(input())):
	(p, q) = map(int, input().split())
	(aa, bb) = map(int, input().split())
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
		(aa, bb) = (bb, aa)
	count = p // a + q // a
	if count <= aa:
		ans = count
	else:
		MAX = 0
		for i in range(aa + 1):
			j = aa - i
			if i * a <= p and j * a <= q:
				pp = p - i * a
				qq = q - j * a
				count = pp // b + qq // b
				MAX = max(MAX, count)
		MAX = min(MAX, bb)
		ans = MAX + aa
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(scnt, wcnt) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(scnt, wcnt) = (wcnt, scnt)
	for i in range(scnt + 1):
		if i * s > p:
			break
		j = (p - i * s) // w
		k = min(scnt - i, f // s)
		l = min(wcnt - j, (f - k * s) // w)
		ans = max(ans, i + j + k + l)
	print(ans)


for t in range(int(input())):
	(p, f) = map(int, input().split())
	(no_sward, no_axe) = map(int, input().split())
	(weight_sward, weight_axe) = map(int, input().split())
	if weight_sward > weight_axe:
		(weight_sward, weight_axe) = (weight_axe, weight_sward)
		(no_sward, no_axe) = (no_axe, no_sward)
	ans = 0
	for s1 in range(no_sward + 1):
		if s1 * weight_sward <= p:
			p_left = p - s1 * weight_sward
			temp_no_sward = no_sward - s1
			a1 = min(no_axe, p_left // weight_axe)
			temp_no_axe = no_axe - a1
			s2 = min(temp_no_sward, f // weight_sward)
			f_left = f - s2 * weight_sward
			a2 = min(f_left // weight_axe, temp_no_axe)
			ans = max(ans, s1 + s2 + a1 + a2)
		else:
			break
	print(ans)


for _ in range(int(input())):
	(p, f) = list(map(int, input().split()))
	(cs, cw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	x = p + f
	c = 0
	fi = 0
	la = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	if cs * s < x:
		fi = cs
		x -= cs * s
		if x > cw * w:
			la = cw
		else:
			la = x // w
	else:
		fi = p // s + f // s
		c += fi
		print(c)
		continue
	c = 0
	for i in range(3):
		if la < i:
			break
		oo = la - i
		for j in range(oo + 1):
			(k, w1) = (p, f)
			k = k - j * w
			w1 = w1 - (oo - j) * w
			if k < 0 or w1 < 0:
				continue
			ea = min(cs, min(k // s, cs) + min(w1 // s, cs))
			c = max(c, ea + oo)
	for i in range(3):
		if fi < i:
			break
		oo = fi - i
		for j in range(oo + 1):
			(k, w1) = (p, f)
			k = k - j * s
			w1 = w1 - (oo - j) * s
			if k < 0 or w1 < 0:
				continue
			ea = min(cw, min(k // w, cw) + min(w1 // w, cw))
			c = max(c, ea + oo)
	print(c)


t = int(input())
while t:
	t += -1
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		if i * s > p:
			break
		t1 = p - i * s
		t2 = min(t1 // w, cntw)
		t3 = cnts - i
		t4 = cntw - t2
		t5 = min(f // s, t3)
		t6 = f - t5 * s
		t7 = min(t6 // w, t4)
		ans = max(ans, i + t2 + t5 + t7)
	print(ans)


t = int(input())
for i in range(t):
	(c0, c1) = map(int, input().split())
	(ma, mb) = map(int, input().split())
	(wa, wb) = map(int, input().split())
	ans = 0
	if wa > wb:
		(wa, wb) = (wb, wa)
		(ma, mb) = (mb, ma)
	for i in range(ma + 1):
		c0a = min(i, c0 // wa)
		c1a = min(ma - i, c1 // wa)
		n0 = c0 - c0a * wa
		n1 = c1 - c1a * wa
		ans0 = c0a + c1a
		c01b = min(mb, n0 // wb + n1 // wb)
		ans0 += c01b
		ans = max(ans, ans0)
	print(ans)


T = int(input())
for _ in range(T):
	(p, f) = tuple(map(int, input().split()))
	(cnts, cntw) = tuple(map(int, input().split()))
	(s, w) = tuple(map(int, input().split()))
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		if i * s > p:
			continue
		sf = i
		ss = min(int(f / s), cnts - i)
		left_f = p - sf * s
		left_s = f - ss * s
		wf = min(cntw, int(left_f / w))
		ws = min(int(left_s / w), cntw - wf)
		ans = max(ans, sf + ss + wf + ws)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	res = 0
	if (s * cs + cw * w <= p) | (s * cs + cw * w <= f):
		print(cs + cw)
		continue
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for i in range(cs + 1):
		if i * s > p:
			break
		count_p_w = (p - i * s) // w
		count_f_s = min(cs - i, f // s)
		count_f_w = min((f - count_f_s * s) // w, cw - count_p_w)
		res = max(res, i + count_p_w + count_f_s + count_f_w)
	print(res)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	ans = 0
	for j in range(cs + 1):
		if j * s > p:
			break
		s1 = j
		s2 = min(cs - j, f // s)
		w1 = min((p - s1 * s) // w, cw)
		w2 = min((f - s2 * s) // w, cw - w1)
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	max_s = min(p // s, cnt_s)
	ans = 0
	for x in range(max_s, -1, -1):
		rest_p = p - s * x
		y = min(f // s, cnt_s - x)
		rest_f = f - s * y
		if rest_p < rest_f:
			(rest_p, rest_f) = (rest_f, rest_p)
		z = min(rest_p // w, cnt_w)
		ans = max(ans, x + y + z + min(rest_f // w, cnt_w - z))
	print(ans)


import math
t = int(input())
for q in range(t):
	(p, f) = [int(i) for i in input().split()]
	(cs, cw) = [int(i) for i in input().split()]
	(s, w) = [int(i) for i in input().split()]
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		ss = min(p // s, i)
		p1 = p - ss * s
		ww = min(p1 // w, cw)
		ss2 = min(f // s, cs - ss)
		f1 = f - ss2 * s
		ww2 = min(f1 // w, cw - ww)
		ans = max(ss + ss2 + ww + ww2, ans)
	print(ans)


from math import log2, ceil
from heapq import heappush, heappop
from copy import deepcopy
from collections import deque, Counter as CC

def main():
	for t in range(int(input())):
		(p, f) = [int(j) for j in input().split()]
		(cts, cntw) = [int(j) for j in input().split()]
		(s, w) = [int(j) for j in input().split()]
		ans = 0
		if s > w:
			(s, w) = (w, s)
			(cts, cntw) = (cntw, cts)
		for x in range(0, min(f // s, cts) + 1):
			tmp = x
			fc = f - x * s
			pc = p
			cs = cts - x
			cw = cntw
			m = min(pc // s, cs)
			tmp += m
			pc -= m * s
			m = min(pc // w, cw)
			tmp += m
			cw -= m
			m = min(fc // w, cw)
			tmp += m
			ans = max(ans, tmp)
		print(ans)
main()


for T in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
		(s, w) = (w, s)
	ans = 0
	for i in range(cnt_s + 1):
		if i * s > p:
			break
		cur = 0
		(cur_s, cur_w) = (cnt_s, cnt_w)
		cur = cur + i
		cur_s = cur_s - i
		temp = min((p - i * s) // w, cur_w)
		cur = cur + temp
		cur_w = cur_w - temp
		temp = min(f // s, cur_s)
		cur = cur + temp
		cur_s = cur_s - temp
		temp = min((f - temp * s) // w, cur_w)
		cur = cur + temp
		ans = max(ans, cur)
	print(ans)


def forf(cap, cs, cw, s, w):
	if s > w:
		return forf(cap, cw, cs, w, s)
	elif cs * s >= cap:
		return cap // s
	else:
		return cs + min(cw, (cap - cs * s) // w)
for t in range(int(input())):
	(p, f) = list(map(int, input().split()))
	(cs, cw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	ans = 0
	for cnt_s in range(cs + 1):
		if cnt_s * s <= p:
			cnt_w = min(cw, (p - cnt_s * s) // w)
			ans = max(ans, cnt_s + cnt_w + forf(f, cs - cnt_s, cw - cnt_w, s, w))
	print(ans)


import sys

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

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))

def check(s, n, v):
	for i in range(n):
		if s[i:i + n].count(v) == 0:
			return False
	return True

def solve():
	(p, f) = mints()
	(cs, cw) = mints()
	(s, w) = mints()
	best = 0
	for i in range(cs + 1):
		if i * s > p:
			break
		h = p - i * s
		j = min(h // w, cw)
		hs = cs - i
		hw = cw - j
		if s < w:
			a = min(f // s, hs)
			b = min((f - a * s) // w, hw)
		else:
			a = min(f // w, hw)
			b = min((f - a * w) // s, hs)
		best = max(best, i + j + a + b)
	print(best)
for i in range(mint()):
	solve()


t = int(input())
for _ in range(t):
	(yy, ff) = map(int, input().split())
	(nns, nnw) = map(int, input().split())
	(ws, ww) = map(int, input().split())
	answers = []
	ns = nns
	nw = nnw
	y = yy
	f = ff
	for i in range(min(ns, y // ws) + 1):
		ns = nns
		nw = nnw
		y = yy
		f = ff
		ls = i
		ns -= ls
		y -= ls * ws
		lw = min(y // ww, nw)
		nw -= lw
		if ws <= ww:
			fs = min(f // ws, ns)
			f -= fs * ws
			fw = min(nw, f // ww)
		else:
			fw = min(f // ww, nw)
			f -= fw * ww
			fs = min(ns, f // ws)
		answers.append(ls + lw + fs + fw)
	print(max(answers))


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 math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(p, f) = map(int, input().split())
	(ns, nw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(ns, nw) = (nw, ns)
	ans = 0
	for i in range(ns + 1):
		ax = i * s
		if ax > p:
			break
		(sc, wc) = (ns - i, nw)
		j = min((p - ax) // w, wc)
		wc -= j
		anss = i + j
		k = min(f // s, sc)
		ff = f - k * s
		l = min(ff // w, wc)
		ans = max(ans, i + j + k + l)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	res = 0
	for cnt_s1 in range(min(cnt_s, p // s) + 1):
		cnt_w1 = min(cnt_w, (p - cnt_s1 * s) // w)
		cnt_s2 = min(cnt_s - cnt_s1, f // s)
		cnt_w2 = min(cnt_w - cnt_w1, (f - cnt_s2 * s) // w)
		res = max(res, cnt_s1 + cnt_s2 + cnt_w1 + cnt_w2)
	print(res)


t = int(input())
while t > 0:
	(c1, c2) = [int(x) for x in input().split()]
	(n1, n2) = [int(x) for x in input().split()]
	(w1, w2) = [int(x) for x in input().split()]
	initial = min(n1, c1 // w1)
	maxi = 0
	for i in range(initial, -1, -1):
		ans = i
		rest_c1 = c1 - i * w1
		ans += min(n2, rest_c1 // w2)
		t_n1 = n1 - i
		t_n2 = n2 - min(n2, rest_c1 // w2)
		if w1 < w2:
			take_n1 = min(t_n1, c2 // w1)
			rest_c2 = c2 - take_n1 * w1
			ans += take_n1
			ans += min(t_n2, rest_c2 // w2)
		else:
			take_n2 = min(t_n2, c2 // w2)
			rest_c2 = c2 - take_n2 * w2
			ans += take_n2
			ans += min(t_n1, rest_c2 // w1)
		maxi = max(maxi, ans)
	print(maxi)
	t -= 1


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		x = min(i, p // s)
		rem = cs - x
		curr = x * s
		y = (p - curr) // w
		remw = cw - y
		xx = min(rem, f // s)
		curr = xx * s
		yy = min(remw, (f - curr) // w)
		ans = max(ans, x + y + xx + yy)
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(p, f) = list(map(int, input().split()))
	(ts, tw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if s > w:
		(w, s) = (s, w)
		(tw, ts) = (ts, tw)
	ans = 0
	for i in range(min(p // s, ts) + 1):
		a = i
		b = min((p - i * s) // w, tw)
		c = min(f // s, ts - i)
		d = min((f - c * s) // w, tw - b)
		ans = max(a + b + c + d, ans)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(w, s) = (s, w)
		(cw, cs) = (cs, cw)
	best = 0
	for swords in range(0, cs + 1):
		if swords * s <= p:
			axes = (p - swords * s) // w
			axes = min(axes, cw)
			rems = cs - swords
			remw = cw - axes
			others = min(f // s, rems)
			otherw = min((f - others * s) // w, remw)
			best = max(best, axes + swords + others + otherw)
	print(best)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
		(s, w) = (w, s)
	result = 0
	for i in range(cnt_s + 1):
		(cur_p, cur_f) = (p, f)
		p_s = i
		if p_s * s > p:
			p_s = p // s
		cur_p -= p_s * s
		f_s = cnt_s - i
		if f_s * s > f:
			f_s = f // s
		cur_f -= f_s * s
		p_w = min(cnt_w, cur_p // w)
		f_w = min(cnt_w - p_w, cur_f // w)
		result = max(result, p_s + p_w + f_s + f_w)
	print(result)


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)
threading.stack_size(2 ** 27)

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

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(p, f) = map(int, input().split())
		(s, a) = map(int, input().split())
		(w1, w2) = map(int, input().split())
		if w1 > w2:
			(w1, w2) = (w2, w1)
			(s, a) = (a, s)
		ans = 0
		for i in range(0, s + 1):
			if i * w1 <= p:
				p_a = min((p - i * w1) // w2, a)
				f_s = min(s - i, f // w1)
				f_a = min(a - p_a, (f - f_s * w1) // w2)
				tp = i + p_a + f_s + f_a
				ans = max(ans, tp)
		print(ans)
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')
main()


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')

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

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	(p, f) = RL()
	(cs, cw) = RL()
	(s, w) = RL()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	res = 0
	for i in range(cs + 1):
		if i * s > p:
			break
		t1 = i
		t2 = min(cw, (p - s * i) // w)
		t3 = min(cs - i, f // s)
		t4 = min(cw - t2, (f - s * t3) // w)
		res = max(res, t1 + t2 + t3 + t4)
	print(res)


for _ in range(int(input())):
	(c1, c2) = map(int, input().split())
	(w1, w2) = map(int, input().split())
	(tw1, tw2) = map(int, input().split())
	if tw2 < tw1:
		(tw1, tw2) = (tw2, tw1)
		(w1, w2) = (w2, w1)
	ans1 = 0
	for i in range(0, w1 + 1):
		if tw1 * i > c1:
			continue
		ans = 0
		oKeep = min(w1 - i, c2 // tw1)
		myLeft = c1 - i * tw1
		hisLeft = c2 - oKeep * tw1
		Myaxe = min(w2, myLeft // tw2)
		hisAxe = min(w2 - Myaxe, hisLeft // tw2)
		ans = i + Myaxe + hisAxe + oKeep
		ans1 = max(ans1, ans)
	print(ans1)


import sys
import math
import collections
import bisect
import itertools
import decimal
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
ni = lambda : int(sys.stdin.readline().rstrip())
ns = lambda : map(int, sys.stdin.readline().rstrip().split())
na = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda : list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))

def main():
	t = ni()
	for _ in range(t):
		(p, f) = ns()
		(cnts, cntw) = ns()
		(s, w) = ns()
		if s > w:
			(cnts, cntw) = (cntw, cnts)
			(s, w) = (w, s)
		ans = 0
		for i in range(min(p // s, cnts) + 1):
			p_s = i
			f_s = min(cnts - i, f // s)
			ts = p - s * p_s
			tf = f - s * f_s
			w_amount = min(cntw, ts // w + tf // w)
			ans = max(ans, p_s + f_s + w_amount)
		print(ans)
main()


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		if i * s > p:
			break
		ans_sub = 0
		nows = cnts - i
		ans_sub += i
		rest1 = p - i * s
		noww = cntw - min(rest1 // w, cntw)
		ans_sub += min(rest1 // w, cntw)
		ans_sub += min(f // s, nows)
		rest2 = f - min(f // s, nows) * s
		ans_sub += min(noww, rest2 // w)
		ans = max(ans, ans_sub)
	print(ans)


t = int(input())

def max_count(cnts, s, cntw, w, l):
	cs = min(cnts, l // s)
	cw = min(cntw, (l - cs * s) // w)
	return (cs, cw)
while t:
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(cnts, cntw) = (cntw, cnts)
		(s, w) = (w, s)
	ans = 0
	for i in range(cnts + 1):
		(cs1, cw1) = max_count(i, s, cntw, w, p)
		(cs2, cw2) = max_count(cnts - cs1, s, cntw - cw1, w, f)
		ans = max(ans, cs1 + cw1 + cs2 + cw2)
	print(ans)
	t -= 1


import sys
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
tt = int(input())
for tc in range(tt):
	(p, f) = sorted(I())
	(p, f) = (f, p)
	(cs, cw) = I()
	(s, w) = I()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		now = i * s
		nan = i
		if now > p:
			break
		(dp, df) = (p, f)
		dp -= now
		(aa, bb) = (cs - i, cw)
		temp = min(dp // w, bb)
		nan += temp
		bb -= temp
		tem = min(aa, f // s)
		nan += tem
		df -= tem * s
		te = min(df // w, bb)
		nan += te
		ans = max(ans, nan)
	print(ans)


import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
	(p, f) = map(int, input().split())
	(Cs, Cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(Cs, Cw) = (Cw, Cs)
	res = 0
	for i in range(Cs + 1):
		if i * s > p:
			break
		tmp = i
		pp = p - i * s
		Csc = Cs - i
		if Csc * s <= f:
			tmp += Csc
			ff = f - Csc * s
		else:
			tmp += f // s
			ff = f % s
		if Cw * w <= pp:
			tmp += Cw
		else:
			tmp += pp // w
			Cwc = Cw - pp // w
			if Cwc * w <= ff:
				tmp += Cwc
			else:
				tmp += ff // w
		res = max(res, tmp)
	print(res)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

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

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		(p, f) = inar()
		(count_s, count_a) = inar()
		(ws, wa) = inar()
		if ws > wa:
			(ws, wa) = (wa, ws)
			(count_s, count_a) = (count_a, count_s)
		ans = 0
		for i in range(count_s + 1):
			if i * ws <= p:
				p_axes = min((p - i * ws) // wa, count_a)
				f_sword = min(count_s - i, f // ws)
				f_axes = min(count_a - p_axes, (f - f_sword * ws) // wa)
				temp = i + p_axes + f_sword + f_axes
				ans = max(ans, temp)
		print(ans)
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')
main()


def controller(p, f, cnt_s, cnt_w, s, w):

	def proc(cap_p, cap_f, cnt, weight):
		(sp, sf) = (cap_p // weight, cap_f // weight)
		if cnt >= sp + sf:
			return (0, sp, sf)
		(sp, sf) = (min(cnt, sp), min(cnt, sf))
		return (cnt, sp, sf)
	if s > w:
		(s, w, cnt_s, cnt_w) = (w, s, cnt_w, cnt_s)
	elif s == w:
		(cnt_s, cnt_w) = (cnt_s + cnt_w, 0)
	(total, sp, sf) = proc(p, f, cnt_s, s)
	if total == 0:
		return sp + sf
	elif cnt_w == 0:
		return cnt_s
	pot_p = p - s * sp
	pot_f = f - s * (cnt_s - sp)
	(total, sp2, sf2) = proc(pot_p, pot_f, cnt_w, w)
	total = total or sp2 + sf2
	total += cnt_s
	rem = pot_p % w + pot_f % w
	if rem >= w and cnt_w > sp2 + sf2:
		for i in range(sp - (cnt_s - sf)):
			pot_p += s
			pot_f -= s
			if pot_p % w + pot_f % w < w:
				return total + 1
	return total

def c_in():
	import sys, os.path
	try:
		file = open(os.path.join(sys.argv[0], '../in-b.txt'))
	except:
		file = sys.stdin
	n_test_case = int(file.readline())
	for i in range(n_test_case):
		(p, f) = [int(i) for i in file.readline().split()]
		(cnt_s, cnt_w) = [int(i) for i in file.readline().split()]
		(s, w) = [int(i) for i in file.readline().split()]
		inputs = (p, f, cnt_s, cnt_w, s, w)
		print(controller(*inputs))
c_in()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	s1 = min(cnt_s, p // s)
	ans = 0
	for i in range(s1 + 1):
		w1 = min(cnt_w, (p - i * s) // w)
		s2 = min(cnt_s - i, f // s)
		w2 = min(cnt_w - w1, (f - s2 * s) // w)
		ans = max(ans, i + w1 + s2 + w2)
	print(ans)


import sys
lines = sys.stdin.read().splitlines()
lincnt = -1

def input():
	global lincnt
	lincnt += 1
	return lines[lincnt]
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, ca) = map(int, input().split())
	(s, a) = map(int, input().split())
	if s < a:
		(s, a) = (a, s)
		(cs, ca) = (ca, cs)
	r = 0
	for pa in range(0, min(ca + 1, 1 + p // a)):
		ps = min(cs, (p - pa * a) // s)
		fa = min(ca - pa, f // a)
		fs = min(cs - ps, (f - fa * a) // s)
		r = max(r, pa + ps + fa + fs)
	print(r)


import sys
T = int(sys.stdin.readline())

def hwa_ga_nan_da(p, f, cs, cw, s, w):
	a = min(p // w, cw)
	p -= a * w
	cw -= a
	b = min(f // s, cs)
	f -= b * s
	cs -= b
	c = min(f // w, cw)
	f -= c * w
	cs -= c
	return a + b + c
for _ in range(T):
	(p, f) = map(int, sys.stdin.readline().split())
	(cs, cw) = map(int, sys.stdin.readline().split())
	(s, w) = list(map(int, sys.stdin.readline().split()))
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	res = 0
	for i in range(cs + 1):
		if i * s > p:
			break
		res = max(res, hwa_ga_nan_da(p - i * s, f, cs - i, cw, s, w) + i)
	print(res)


t = int(input())
for _ in range(t):
	(p, f) = [int(i) for i in input().split(' ')]
	(cnts, cntw) = [int(i) for i in input().split(' ')]
	(s, w) = [int(i) for i in input().split(' ')]
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	max_itens = 0
	for i in range(min(p // s, cnts) + 1):
		A = i
		B = min((p - s * A) // w, cntw)
		C = min(f // s, cnts - A)
		D = min((f - s * C) // w, cntw - B)
		max_itens = max(max_itens, A + B + C + D)
	print(max_itens)


TC = int(input())
while TC > 0:
	cap = list(map(int, input().split()))
	cnt = list(map(int, input().split()))
	wei = list(map(int, input().split()))
	cap = sorted(cap)
	if wei[0] > wei[1]:
		(wei[0], wei[1]) = (wei[1], wei[0])
		(cnt[0], cnt[1]) = (cnt[1], cnt[0])
	ans = 0
	for x1 in range(cnt[0] + 1):
		if x1 * wei[0] > cap[0]:
			continue
		y1 = min(cnt[1], (cap[0] - x1 * wei[0]) // wei[1])
		cnt[0] -= x1
		cnt[1] -= y1
		x2 = min(cnt[0], cap[1] // wei[0])
		y2 = min(cnt[1], (cap[1] - x2 * wei[0]) // wei[1])
		ans = max(ans, x1 + y1 + x2 + y2)
		cnt[0] += x1
		cnt[1] += y1
	print(ans)
	TC -= 1


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for x1 in range(cnts + 1):
		if x1 * s > p:
			break
		y1 = min(cntw, (p - s * x1) // w)
		x2 = min(cnts - x1, f // s)
		y2 = min(cntw - y1, (f - s * x2) // w)
		ans = max(ans, x1 + x2 + y1 + y2)
	print(ans)


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 bisect
for j in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	minny = min(p, f)
	maxy = max(p, f)
	if w <= s:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	arr1 = []
	arr2 = []
	for i in range(cs + 1):
		if i * s <= minny:
			arr1.append(i)
		if i * s <= maxy:
			arr2.append(i)
	max1 = 0
	for i in range(len(arr1)):
		swords = arr1[i]
		axes = max((minny - swords * s) // w, 0)
		axes = min(cw, axes)
		cs1 = cs - swords
		cw1 = cw - axes
		search = min(cs - swords, maxy // s)
		ind = min(bisect.bisect_left(arr2, search), len(arr2) - 1)
		s1 = arr2[ind]
		a1 = max((maxy - s1 * s) // w, 0)
		a1 = min(cw1, a1)
		if swords + axes + s1 + a1 > max1:
			max1 = swords + axes + s1 + a1
	print(max1)


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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 count1(s):
	c = 0
	for i in s:
		if i == '1':
			c += 1
	return c

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

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True
for xyz in range(0, int(input())):
	(p, f) = map(int, input().split())
	(p, f) = (max(p, f), min(p, f))
	(ns, na) = map(int, input().split())
	(ws, wa) = map(int, input().split())
	if ws > wa:
		(ws, wa) = (wa, ws)
		(ns, na) = (na, ns)
	ans = -1
	for i in range(0, ns + 1):
		ps = min(i, p // ws)
		pleft = p - ps * ws
		sl = ns - ps
		fs = min(sl, f // ws)
		fleft = f - fs * ws
		pa = min(na, pleft // wa)
		al = na - pa
		fa = min(al, fleft // wa)
		ans = max(ans, fa + pa + fs + ps)
	print(ans)


def solve():
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		if i * s > p:
			continue
		sword_first = i
		sword_second = min(f // s, cnts - sword_first)
		left_first = p - sword_first * s
		left_second = f - sword_second * s
		waraxe_first = min(cntw, left_first // w)
		waraxe_second = min(left_second // w, cntw - waraxe_first)
		ans = max(ans, sword_first + sword_second + waraxe_first + waraxe_second)
	print(ans)
for _ in range(int(input())):
	solve()


for t in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for i in range(0, cs + 1):
		if i * s > p:
			continue
		j = min(cw, (p - i * s) // w)
		(rs, rw) = (cs - i, cw - j)
		x = min(rs, f // s)
		y = min(rw, (f - x * s) // w)
		ans = max(ans, i + j + x + y)
	print(ans)


from sys import stdin, stdout
import heapq as hp

def findBest(C, N1, N2, W1, W2):
	if W1 > W2:
		return findBest(C, N2, N1, W2, W1)
	A = min(N1, C // W1)
	B = min(N2, (C - A * W1) // W2)
	return A + B

def find(C1, C2, N1, N2, W1, W2):
	M = 0
	for i in range(min(N1, C1 // W1) + 1):
		A = i
		B = min(N2, (C1 - i * W1) // W2)
		M = max(M, A + B + findBest(C2, N1 - i, N2 - B, W1, W2))
	return M

def main():
	for _ in range(int(stdin.readline())):
		(C1, C2) = list(map(int, stdin.readline().split()))
		(N1, N2) = list(map(int, stdin.readline().split()))
		(W1, W2) = list(map(int, stdin.readline().split()))
		print(find(C1, C2, N1, N2, W1, W2))
main()


for _ in range(int(input())):
	(inip, inif) = [int(i) for i in input().split()]
	(cnts, cntw) = [int(i) for i in input().split()]
	(s, w) = [int(i) for i in input().split()]
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	if inif > inip:
		(inif, inip) = (inip, inif)
	ini = cnts + cntw
	inis = cnts
	iniw = cntw
	ans = 0
	for i in range(cnts + 1):
		p = inip
		f = inif
		cnts = inis
		cntw = iniw
		if p >= i * s:
			p -= i * s
			cnts -= i
		else:
			break
		if p > cntw * w:
			cp = cntw * w
			cntw = 0
		else:
			cp = p // w * w
			cntw -= p // w
		if f > cnts * s:
			cf = cnts * s
			cnts = 0
		else:
			cf = f // s * s
			cnts -= f // s
		f -= cf
		if f > cntw * w:
			cf = cntw * w
			cntw = 0
		else:
			cf = f // w * w
			cntw -= f // w
		f -= cf
		ans = max(ans, ini - cnts - cntw)
	print(ans)


for i in range(int(input())):
	(p, q) = map(int, input().split())
	(cnts, cntw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if s > w:
		t = s
		s = w
		w = t
		t = cnts
		cnts = cntw
		cntw = t
	ans = 0
	for x1 in range(0, min(cnts, p // s) + 1):
		y1 = min(cntw, (p - x1 * s) // w)
		x2 = min(cnts - x1, q // s)
		y2 = min(cntw - y1, (q - x2 * s) // w)
		ans = max(ans, x1 + x2 + y1 + y2)
	print(ans)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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 = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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:
			self.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 get_int():
	return int(input())

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

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().strip()

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	n = get_int()
	s = get_str()
	return s[::2]

def solve_b():
	(p, f) = get_ints()
	(cnt_s, cnt_w) = get_ints()
	(s, w) = get_ints()
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	best = 0
	for swords in range(cnt_s + 1):
		curr = 0
		(p_copy, f_copy) = (p, f)
		(cnt_s_copy, cnt_w_copy) = (cnt_s, cnt_w)
		if swords * s > p:
			break
		p_copy -= s * swords
		cnt_s_copy -= swords
		curr += swords
		axes = min(cnt_w_copy, p_copy // w)
		cnt_w_copy -= axes
		curr += axes
		p_copy -= w * axes
		swords2 = min(cnt_s_copy, f_copy // s)
		cnt_s_copy -= swords2
		curr += swords2
		f_copy -= s * swords2
		axes2 = min(cnt_w_copy, f_copy // w)
		cnt_w_copy -= axes2
		curr += axes2
		f_copy -= w * axes2
		best = max(curr, best)
	return best

def solve_c():
	s = get_str()
	n = len(s)
	x = get_int()
	w = ['1'] * n
	for i in range(n):
		if s[i] == '0':
			if i >= x:
				w[i - x] = '0'
			if i + x < n:
				w[i + x] = '0'
	for i in range(n):
		if s[i] == '1':
			good = False
			if i >= x:
				if w[i - x] == '1':
					good = True
			if i + x < n:
				if w[i + x] == '1':
					good = True
			if not good:
				return -1
	return ''.join(w)
t = get_int()
for _ in range(t):
	print(solve_b())


def fun2(p, f, s, w, cs, cw):
	xs = min(cs, f // s)
	f -= s * xs
	xw = min(cw, p // w + f // w)
	return xs + xw

def fun():
	(p, f) = map(int, input().split(' '))
	(cs, cw) = map(int, input().split(' '))
	(s, w) = map(int, input().split(' '))
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		if i * s <= p:
			ans = max(ans, fun2(p - i * s, f, s, w, cs - i, cw) + i)
		if i * s <= f:
			ans = max(ans, fun2(f - i * s, p, s, w, cs - i, cw) + i)
	return ans

def solve():
	t = int(input())
	for i in range(t):
		print(fun())
solve()


import sys
import math

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

def main():
	(p, f) = map(int, input().split())
	(s, w) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	ans = 0
	if cs > cw:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	for s1 in range(0, min(s, p // cs) + 1):
		w1 = min(w, (p - cs * s1) // cw)
		s2 = min(s - s1, f // cs)
		w2 = min(w - w1, (f - cs * s2) // cw)
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)
t = int(input())
for i in range(t):
	main()


tests = int(input())
answers = []
for _ in range(tests):
	(cap1, cap2) = [int(i) for i in input().split()]
	(n1, n2) = [int(i) for i in input().split()]
	(light, heavy) = [int(i) for i in input().split()]
	if light > heavy:
		(n1, n2) = (n2, n1)
		(cap1, cap2) = (cap2, cap1)
		(light, heavy) = (heavy, light)
	ans = 0
	for heavy_used_by_1 in range(min(n2, cap1 // heavy) + 1):
		cap_left_1 = cap1 - heavy_used_by_1 * heavy
		pot = heavy_used_by_1
		light_used_by_1 = min(n1, cap_left_1 // light)
		pot += light_used_by_1
		left_light = n1 - light_used_by_1
		light_used_by_2 = min(left_light, cap2 // light)
		cap_left_2 = cap2 - light_used_by_2 * light
		pot += light_used_by_2
		pot += min(n2 - heavy_used_by_1, cap_left_2 // heavy)
		ans = max(ans, pot)
	answers.append(ans)
print(*answers, sep='\n')


def solve(p, f, cnt_s, cnt_w, s, w):
	if s > w:
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
		(s, w) = (w, s)
	r = 0
	for a in range(cnt_s + 1):
		if a * s > p:
			continue
		b = (p - a * s) // w
		b = min(b, cnt_w)
		c = min(f // s, cnt_s - a)
		d = (f - c * s) // w
		d = min(d, cnt_w - b)
		r = max(r, a + b + c + d)
	return r
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	res = solve(p, f, cnt_s, cnt_w, s, w)
	print(res)


TC = int(input())
for tc in range(TC):
	(P, F) = map(int, input().split())
	(CS, CW) = map(int, input().split())
	(S, W) = map(int, input().split())
	if W < S:
		(S, W) = (W, S)
		(CS, CW) = (CW, CS)
	maxp = P // S
	maxf = F // S
	if maxp + maxf <= CS:
		print(maxp + maxf)
		continue
	result = 0
	for i in range(min(P // W, CW) + 1):
		p = P - i * W
		cs1 = min(p // S, CS)
		cs2 = CS - cs1
		f = F - cs2 * S
		if f < 0:
			continue
		cw2 = min(f // W, CW - i)
		r = i + CS + cw2
		result = max(result, r)
	print(result)


def solve():
	(p, f) = map(int, input().split())
	(nums, numw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(nums, numw) = (numw, nums)
	ans = -1
	for i in range(nums + 1):
		if i * s <= p:
			pp = p - i * s
			j = min(f // s, nums - i)
			ff = f - j * s
			k = min(pp // w, numw)
			l = min(ff // w, numw - k)
			ans = max(ans, i + j + k + l)
	print(ans)
T = int(input())
for case in range(T):
	solve()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

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

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

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

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

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	for _ in range(int(input())):
		(p, f) = map(int, input().split())
		(cs, cw) = map(int, input().split())
		(s, w) = map(int, input().split())
		ans = 0
		if s > w:
			(s, w) = (w, s)
			(cs, cw) = (cw, cs)
		for s1 in range(min(cs, p // s) + 1):
			w1 = min(cw, (p - s * s1) // w)
			s2 = min(cs - s1, f // s)
			w2 = min(cw - w1, (f - s2 * s) // w)
			ans = max(s1 + s2 + w1 + w2, ans)
		print(ans)
solve()


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(ptemp, ftemp) = map(int, input().split())
	(cstemp, cwtemp) = map(int, input().split())
	(stemp, wtemp) = map(int, input().split())
	p = max(ptemp, ftemp)
	f = min(ptemp, ftemp)
	cs = cstemp
	cw = wtemp
	s = stemp
	w = wtemp
	cs = cstemp
	cw = cwtemp
	if wtemp > stemp:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(-1, cw):
		temp = 0
		if p - (i + 1) * w >= 0:
			temp = i + 1
			countS = (p - (i + 1) * w) // s
			x = min(countS, cs)
			temp += x
			tempCS = cs - x
			tempCountW = cw - (i + 1)
			countW = f // w
			y = min(countW, tempCountW)
			temp += y
			tempF = f - y * w
			countS2 = tempF // s
			z = min(countS2, tempCS)
			temp += z
			ans = max(ans, temp)
	print(ans)


def solve(p, f, ns, na, ws, wa):
	if ws > wa:
		(ws, wa) = (wa, ws)
		(ns, na) = (na, ns)
	best = 0
	for i in range(ns + 1):
		mySwordCount = i
		mySwordCost = i * ws
		if mySwordCost <= p:
			rem_p = p - mySwordCost
			myWarAxeCount = min(rem_p // wa, na)
			remSwords = ns - mySwordCount
			remWarAxe = na - myWarAxeCount
			otherSwordCount = min(f // ws, remSwords)
			rem_f = f - otherSwordCount * ws
			otherWarAxeCount = min(rem_f // wa, remWarAxe)
			best = max(best, myWarAxeCount + mySwordCount + otherWarAxeCount + otherSwordCount)
	return best
t = int(input())
for _ in range(t):
	(capOfP, capOfF) = map(int, input().split())
	(numOfSword, numOfWarAxe) = map(int, input().split())
	(weightOfSword, weightOfWarAxe) = map(int, input().split())
	print(solve(capOfP, capOfF, numOfSword, numOfWarAxe, weightOfSword, weightOfWarAxe))


t = int(input())
for _ in range(t):
	(p, f) = list(map(int, input().split(' ')))
	(cnts, cntw) = list(map(int, input().split(' ')))
	(s, w) = list(map(int, input().split(' ')))
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	most_can_take = min(cnts, p // s)
	ret = 0
	for i in range(most_can_take + 1):
		i_take_w = min(cntw, (p - i * s) // w)
		s_left = cnts - i
		w_left = cntw - i_take_w
		f_take_s = min(s_left, f // s)
		f_take_w = min(w_left, (f - f_take_s * s) // w)
		ret = max(ret, i + i_take_w + f_take_s + f_take_w)
	print(ret)


def solve():
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	for k in range(0, cs + 1):
		max_pcs = min(p // s, k)
		max_fcs = min(f // s, cs - k)
		rp = p - s * max_pcs
		rf = f - s * max_fcs
		max_pcw = rp // w
		max_fcw = rf // w
		total = max_pcs + max_fcs + min(max_pcw + max_fcw, cw)
		ans = max(ans, total)
	for k in range(0, cw + 1):
		max_pcw = min(p // w, k)
		max_fcw = min(f // w, cw - k)
		rp = p - w * max_pcw
		rf = f - w * max_fcw
		max_pcs = rp // s
		max_fcs = rf // s
		total = max_pcw + max_fcw + min(max_pcs + max_fcs, cs)
		ans = max(ans, total)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for tt in range(t):
	ss = input().split(' ')
	p = int(ss[0])
	f = int(ss[1])
	if p > f:
		(p, f) = (f, p)
	ss = input().split(' ')
	cs = int(ss[0])
	cw = int(ss[1])
	ss = input().split(' ')
	s = int(ss[0])
	w = int(ss[1])
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = int(0)
	if s != w:
		for i in range(cs + 1):
			rs = cs - i
			l1 = p - i * s
			if l1 < 0:
				break
			r1 = min(int(l1 / w), cw)
			rw = cw - r1
			r2 = min(int(f / s), rs)
			l2 = f - r2 * s
			r3 = min(int(l2 / w), rw)
			ans = max(ans, r1 + r2 + r3 + i)
	else:
		ans = min(int(p / s) + int(f / s), cs + cw)
	print(ans)


def ints():
	return map(int, input().split())
for _ in range(int(input())):
	(p, f) = ints()
	(cs, cw) = ints()
	(s, w) = ints()
	ans = 0
	for i in range(cs + 1):
		rem = p - i * s
		if rem < 0:
			break
		j = min(cw, rem // w)
		t1 = i + j
		ccs = cs - i
		ccw = cw - j
		if s < w:
			t2 = min(ccs, f // s)
			ff = f - t2 * s
			t2 += min(ccw, ff // w)
		else:
			t2 = min(ccw, f // w)
			ff = f - t2 * w
			t2 += min(ccs, ff // s)
		ans = max(ans, t1 + t2)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	(s, w) = map(int, input().split())
	xx = min(c1, p // s)
	ans = 0
	for i in range(0, xx + 1):
		tem = 0
		cc = p - s * i
		tem += i
		axe = min(c2, cc // w)
		tem += axe
		left = c2 - axe
		if s <= w:
			swo = min(c1 - i, f // s)
			tem += swo
			cc = f - swo * s
			tem += min(left, cc // w)
		else:
			axe = min(left, f // w)
			tem += axe
			cc = f - axe * w
			tem += min(c1 - i, cc // s)
		ans = max(ans, tem)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(p, f) = [int(i) for i in input().split()]
	(c1, c2) = [int(i) for i in input().split()]
	(w1, w2) = [int(i) for i in input().split()]
	if w1 > w2:
		(c1, c2) = (c2, c1)
		(w1, w2) = (w2, w1)
	if p > f:
		(p, f) = (f, p)
	res = 0
	for i in range(0, min(c1, p // w1) + 1):
		rem_p = p - i * w1
		p_c2 = min(rem_p // w2, c2)
		j = min(f // w1, c1 - i)
		rem_f = f - j * w1
		f_c2 = min(rem_f // w2, c2 - p_c2)
		res = max(res, i + p_c2 + j + f_c2)
	print(res)


import sys
from collections import defaultdict as dc
from operator import itemgetter
input = sys.stdin.readline
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(s, w) = map(int, input().split())
	(sw, ww) = map(int, input().split())
	if sw > ww:
		(sw, ww) = (ww, sw)
		(s, w) = (w, s)
	m = 0
	for i in range(s + 1):
		if i * sw <= p:
			ps = i
			tp = p - i * sw
			pw = min(w, tp // ww)
			fs = min(s - i, f // sw)
			tf = f - fs * sw
			fw = min(w - pw, tf // ww)
			m = max(m, ps + pw + fs + fw)
		else:
			break
	print(m)


import sys

def i():
	return sys.stdin.readline()[:-1]
cases = int(i())
for x in range(cases):
	(p, f) = map(int, i().split())
	(cs, cw) = map(int, i().split())
	(s, w) = map(int, i().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	pMax = p // s
	fMax = f // s
	if pMax + fMax <= cs:
		print(pMax + fMax)
	else:
		currTotal = 0
		for y in range(cs + 1):
			pHold = p - y * s
			fHold = f - (cs - y) * s
			if pHold >= 0 and fHold >= 0:
				currTotal = max(currTotal, min(cw, pHold // w + fHold // w))
		print(cs + currTotal)


t = int(input(''))
for _ in range(t):
	[p, f] = list(map(int, input().split()))
	[cnts, cntw] = list(map(int, input().split()))
	[s, w] = list(map(int, input().split()))
	ans = 0
	if s > w:
		temp = s
		s = w
		w = temp
		temp1 = cnts
		cnts = cntw
		cntw = temp1
	for i in range(min(cnts, p // s) + 1):
		w1 = min(cntw, (p - s * i) // w)
		s2 = min(cnts - i, f // s)
		w2 = min(cntw - w1, (f - s * s2) // w)
		ans = max(ans, i + w1 + s2 + w2)
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		max_weights = _read_ints()
		items_amounts = _read_ints()
		items_weights = _read_ints()
		result = compute_max_ingots_n(max_weights, items_amounts, items_weights)
		print(result)

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

def compute_max_ingots_n(max_weights, items_amounts, items_weights):
	(max_weight_1, max_weight_2) = max_weights
	(a_max_n, b_max_n) = items_amounts
	(a_weight, b_weight) = items_weights
	get_b1_n_by_a1_n = lambda a_n: min((max_weight_1 - a_n * a_weight) // b_weight, b_max_n)
	sets_1_variants = [(a_n, get_b1_n_by_a1_n(a_n)) for a_n in range(0, min(a_max_n + 1, max_weight_1 // a_weight + 1))]
	sets_2_variants = [_find_best_items_set(max_weight_2, (a_max_n - a1_n, b_max_n - b1_n), (a_weight, b_weight)) for (a1_n, b1_n) in sets_1_variants]
	return max((a1 + b1 + a2 + b2 for ((a1, b1), (a2, b2)) in zip(sets_1_variants, sets_2_variants)))

def _find_best_items_set(max_weight, items_amounts, items_weights):
	(max_a_n, max_b_n) = items_amounts
	(a_weight, b_weight) = items_weights
	if not a_weight <= b_weight:
		(a_weight, b_weight) = (b_weight, a_weight)
		(max_a_n, max_b_n) = (max_b_n, max_a_n)
	selected_a = min(max_a_n, max_weight // a_weight)
	remain_for_b = max_weight - a_weight * selected_a
	selected_b = min(remain_for_b // b_weight, max_b_n)
	result = (selected_a, selected_b)
	return result
main()


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, cs, w, cw) = (w, cw, s, cs)
	res = 0
	for i in range(cs + 1):
		if p < s * i:
			continue
		val = i
		pw = min(int((p - s * i) / w), cw)
		val += pw
		(rs, rw) = (cs - i, cw - pw)
		fs = min(int(f / s), rs)
		val += fs
		fw = min(int((f - s * fs) / w), rw)
		val += fw
		res = max(res, val)
	print(res)


def main():
	(myCapacity, folCapacity) = map(int, input().strip().split())
	(swords, axes) = map(int, input().strip().split())
	(swordWeight, axeWeight) = map(int, input().strip().split())
	if swordWeight > axeWeight:
		(swordWeight, axeWeight) = (axeWeight, swordWeight)
		(swords, axes) = (axes, swords)
	maxWeapons = 0
	for takenSword in range(swords + 1):
		if takenSword * swordWeight > myCapacity:
			continue
		folTakenSword = min(swords - takenSword, folCapacity // swordWeight)
		leftMyCapacity = myCapacity - swordWeight * takenSword
		leftFolCapacity = folCapacity - swordWeight * folTakenSword
		takenAxe = min(leftMyCapacity // axeWeight, axes)
		folTakenAxe = min(leftFolCapacity // axeWeight, axes - takenAxe)
		maxWeapons = max(maxWeapons, takenSword + folTakenSword + takenAxe + folTakenAxe)
	print(maxWeapons)
for _ in range(int(input())):
	main()


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')

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

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def solve():
	(P, F) = mpint()
	(CS, CW) = mpint()
	(S, W) = mpint()
	if S > W:
		(S, W) = (W, S)
		(CS, CW) = (CW, CS)
	if P > F:
		(P, F) = (F, P)
	ans = ps = 0
	while ps <= CS and ps * S <= P:
		p = P - ps * S
		cs = CS - ps
		pw = min(CW, p // W)
		cw = CW - pw
		fs = min(cs, F // S)
		f = F - S * fs
		fw = min(cw, f // W)
		ans = max(ans, ps + pw + fs + fw)
		ps += 1
	return ans

def main():
	for _ in range(itg()):
		print(solve())
DEBUG = 0
URL = 'https://codeforces.com/contest/1400/problem/B'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 3:
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG:
		_print = print

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cntS, cntW) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(s, w) = (w, s)
		(cntS, cntW) = (cntW, cntS)
	ans = 0
	for s1 in range(0, min(int(p / s), cntS) + 1):
		w1 = min(cntW, int((p - s * s1) // w))
		s2 = min(cntS - s1, int(f // s))
		w2 = min(cntW - w1, int((f - s * s2) // w))
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)


for nt in range(int(input())):
	(p, f) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	(s, w) = map(int, input().split())
	(p, f) = (max(p, f), min(p, f))
	if s > w:
		(w, s) = (s, w)
		(c1, c2) = (c2, c1)
	ans = 0
	for i in range(c1 + 1):
		if i * s <= p:
			ans = max(ans, i + min(c2, (p - i * s) // w) + min(c1 - i, f // s) + min(max(0, c2 - (p - i * s) // w), max(0, f - (c1 - i) * s) // w))
	print(ans)


LIGHT = 0
HEAVY = 1

def calc_deep(p, s):
	res = 0
	d_weight = s[HEAVY]['weight'] - s[LIGHT]['weight']
	first = True
	power = p[0]
	light = min(power // s[LIGHT]['weight'], s[LIGHT]['count'])
	power -= light * s[LIGHT]['weight']
	heavy = min(power // s[HEAVY]['weight'], s[HEAVY]['count'])
	power -= heavy * s[HEAVY]['weight']
	cases = list()
	cases.append((light, heavy))
	while light > 0:
		dlight = min(light, (s[HEAVY]['weight'] - power + s[LIGHT]['weight'] - 1) // s[LIGHT]['weight'])
		light -= dlight
		power += dlight * s[LIGHT]['weight']
		dheavy = min(power // s[HEAVY]['weight'], s[HEAVY]['count'] - heavy)
		if dheavy > 0:
			heavy += dheavy
			power -= s[HEAVY]['weight'] * dheavy
			cases.append((light, heavy))
		else:
			break
	best_amount = 0
	for case in cases:
		power = p[1]
		light = min(power // s[LIGHT]['weight'], s[LIGHT]['count'] - case[LIGHT])
		power -= light * s[LIGHT]['weight']
		heavy = min(power // s[HEAVY]['weight'], s[HEAVY]['count'] - case[HEAVY])
		power -= heavy * s[HEAVY]['weight']
		best_amount = max(best_amount, light + heavy + case[LIGHT] + case[HEAVY])
	return best_amount

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def seq2str(seq):
	return ' '.join((str(item) for item in seq))
a = get_ints()
assert len(a) == 1
t = a[0]
for i in range(t):
	a = get_ints()
	assert len(a) == 2
	p = [a[0], a[1]] if a[0] <= a[1] else [a[1], a[0]]
	(s0, s1) = (dict(), dict())
	a = get_ints()
	assert len(a) == 2
	(s0['count'], s1['count']) = (a[0], a[1])
	a = get_ints()
	assert len(a) == 2
	(s0['weight'], s1['weight']) = (a[0], a[1])
	s = [s0, s1] if s0['weight'] <= s1['weight'] else [s1, s0]
	res = calc_deep(p, s)
	print(res)


import sys
import bisect
input = sys.stdin.readline
t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	(cy, cf) = map(int, input().split())
	(s, a) = map(int, input().split())
	(sw, aw) = map(int, input().split())
	l = []
	l.append([sw, s])
	l.append([aw, a])
	l.sort()
	l1 = []
	l1.append([l[0][0], l[0][1]])
	l1.append([l[1][0], l[1][1]])
	ans = 0
	for i in range(l[0][1] + 1):
		(x, y) = (i, l[0][1] - i)
		l1[0][0] = l[0][0]
		l1[0][1] = l[0][1]
		l1[1][0] = l[1][0]
		l1[1][1] = l[1][1]
		ans1 = 0
		(cf1, cy1) = (cf, cy)
		if x * l[0][0] <= cy1:
			ans1 = x
			cy1 -= x * l[0][0]
		else:
			continue
		if cf1 < y * l[0][0]:
			ans1 += cf1 // l[0][0]
			cf1 -= l[0][0] * (cf1 // l[0][0])
		else:
			ans1 += y
			cf1 -= y * l[0][0]
		if l1[1][1] > cy1 // l1[1][0]:
			l1[1][1] -= cy1 // l1[1][0]
			ans1 += cy1 // l1[1][0]
			cy1 -= l1[1][0] * (cy1 // l1[1][0])
		else:
			ans1 += l1[1][1]
			cy1 -= l1[1][0] * l1[1][1]
			l1[1][1] = 0
		if l1[1][1] > cf1 // l1[1][0]:
			ans1 += cf1 // l1[1][0]
			l1[1][1] -= cf1 // l1[1][0]
			cf1 -= l1[1][0] * (cf1 // l1[1][0])
		else:
			ans1 += l1[1][1]
			cf1 -= l1[1][0] * l1[1][1]
			l1[1][1] = 0
		ans = max(ans, ans1)
	print(ans)


z = lambda : map(int, input().split())
k = lambda *x: (min(*x), max(*x))
for _ in range(int(input())):
	(p, f) = z()
	(x, y) = z()
	(s, w) = z()
	(a, b) = k((s, x), (w, y))
	(c, d) = (a[0], b[0])
	e = p // c + f // c
	if e <= a[1]:
		print(e)
	else:
		m = 0
		for i in range(a[1] + 1):
			(g, h) = (p - i * c, f - (a[1] - i) * c)
			if min(g, h) >= 0:
				v = g // d + h // d
				m = max(min(v, b[1]), m)
		print(a[1] + m)


t = lambda : range(int(input()))
a = lambda : list(map(int, input().split()))
for _ in t():
	(p, f) = a()
	(cs, cw) = a()
	(s, w) = a()
	if s > w:
		t = w
		ts = cw
		w = s
		cw = cs
		s = t
		cs = ts
	ans = 0
	for a0 in range(0, min(cs, p // s) + 1):
		b0 = min(cw, (p - a0 * s) // w)
		a1 = min(cs - a0, f // s)
		b1 = min(cw - b0, (f - a1 * s) // w)
		ans = max(ans, a0 + a1 + b0 + b1)
	print(ans)


for _ in range(int(input())):
	(p, f) = [int(i) for i in input().split()]
	(cs, cw) = [int(i) for i in input().split()]
	(s, w) = [int(i) for i in input().split()]
	if s < w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	result = 0
	for ps in range(cs + 1):
		if ps * s > p:
			break
		pw = min((p - ps * s) // w, cw)
		fw = min(f // w, cw - pw)
		fs = min((f - fw * w) // s, cs - ps)
		result = max(result, ps + pw + fs + fw)
	print(result)


import math
t = int(input())

def take(f, cts, ctw, s, w):
	if s > w:
		if w * ctw > f:
			return f // w
		else:
			return ctw + min(cts, math.floor((f - ctw * w) / s))
	elif s * cts > f:
		return f // s
	else:
		return cts + min(ctw, math.floor((f - cts * s) / w))

def calc(p, f, cts, ctw, s, w):
	ans = 0
	for i in range(cts + 1):
		x = i
		if s * x <= p:
			y = max(0, min(ctw, math.floor((p - x * s) / w)))
			ans = max(ans, x + y + take(f, cts - x, ctw - y, s, w))
	return ans
for _ in range(t):
	(p, f) = map(int, input().strip().split())
	(cts, ctw) = map(int, input().strip().split())
	(s, w) = map(int, input().strip().split())
	print(calc(p, f, cts, ctw, s, w))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = []
	if s > w:
		(s, w, cnt_s, cnt_w) = (w, s, cnt_w, cnt_s)
	for p_s in range(min(cnt_s, p // s) + 1):
		p_w = min(cnt_w, (p - s * p_s) // w)
		f_s = min(cnt_s - p_s, f // s)
		f_w = min(cnt_w - p_w, (f - f_s * s) // w)
		ans.append(p_s + p_w + f_s + f_w)
	print(max(ans))


T = int(input())
for i in range(T):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	(P, F, CS, CW, S, W) = (p, f, cs, cw, s, w)
	PERFECT = False
	total = 0
	taken = min(p // s, cs)
	cs -= taken
	p -= taken * s
	total += taken
	taken = min(p // w, cw)
	cw -= taken
	p -= taken * w
	total += taken
	taken = min(f // s, cs)
	cs -= taken
	f -= taken * s
	total += taken
	taken = min(f // w, cw)
	cw -= taken
	f -= taken * w
	total += taken
	max_total = total
	if p == 0 and f == 0:
		PERFECT = True
	if PERFECT:
		print(max_total)
	else:
		repeat1 = CW - cw
		repeat2 = CS - cs
		for j in range(1, repeat1 + 1):
			if P >= j * w:
				(p, f, cs, cw, s, w) = (P, F, CS, CW, S, W)
				total = j
				p -= j * w
				cw -= j
				taken = min(p // s, cs)
				cs -= taken
				p -= taken * s
				total += taken
				taken = min(p // w, cw)
				cw -= taken
				p -= taken * w
				total += taken
				taken = min(f // s, cs)
				cs -= taken
				f -= taken * s
				total += taken
				taken = min(f // w, cw)
				cw -= taken
				f -= taken * w
				total += taken
				max_total = max(total, max_total)
				if p == 0 and f == 0:
					PERFECT = True
				if PERFECT:
					break
		if not PERFECT:
			for j in range(1, 1 + repeat2):
				if F >= j * s:
					(p, f, cs, cw, s, w) = (P, F, CS, CW, S, W)
					total = j
					f -= j * s
					cs -= j
					taken = min(p // s, cs)
					cs -= taken
					p -= taken * s
					total += taken
					taken = min(p // w, cw)
					cw -= taken
					p -= taken * w
					total += taken
					taken = min(f // s, cs)
					cs -= taken
					f -= taken * s
					total += taken
					taken = min(f // w, cw)
					cw -= taken
					f -= taken * w
					total += taken
					max_total = max(total, max_total)
					if p == 0 and f == 0:
						PERFECT = True
					if PERFECT:
						break
		print(max_total)


scan = lambda : map(int, input().split())
for _ in range(int(input())):
	(f, p) = scan()
	(cnt_s, cnt_w) = scan()
	(s, w) = scan()
	ans = -1
	(s, w, cnt_s, cnt_w) = (w, s, cnt_w, cnt_s) if s > w else (s, w, cnt_s, cnt_w)
	for i in range(cnt_s + 1):
		if i * s > p:
			break
		swp = i
		swf = min(cnt_s - swp, f // s)
		axwp = min(cnt_w, (p - swp * s) // w)
		axwf = min(cnt_w - axwp, (f - s * swf) // w)
		ans = max(ans, swp + swf + axwp + axwf)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	P = p // s
	F = f // s
	if P + F < cs:
		print(P + F)
	else:
		ans = cs
		for i in range(max(0, cs - F), min(P + 1, cs + 1)):
			ans = max(ans, cs + (p - s * i) // w + (f - s * (cs - i)) // w)
		print(min(ans, cs + cw))


def f(w1, w2, c1, c2, p):
	if w1 > w2:
		return f(w2, w1, c2, c1, p)
	if c1 * w1 >= p:
		return p // w1
	return c1 + min(c2, (p - c1 * w1) // w2)
for _ in range(int(input())):
	(x, y) = [int(i) for i in input().split()]
	(c1, c2) = [int(i) for i in input().split()]
	(w1, w2) = [int(i) for i in input().split()]
	ans = 0
	for i in range(c1 + 1):
		if i * w1 <= x:
			k = min((x - i * w1) // w2, c2)
			ans = max(ans, i + k + f(w1, w2, c1 - i, c2 - k, y))
		else:
			break
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w, cs, cw) = (w, s, cw, cs)
	ans = 0
	for i in range(cs + 1):
		if s * i > p:
			break
		ww = min((p - s * i) // w, cw)
		ss = min(cs - i, f // s)
		tmp = i + ww + ss + min((f - s * ss) // w, cw - ww)
		ans = max(tmp, ans)
	print(ans)


import bisect
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

def solve(p, f, cnts, cntw, s, w):
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(0, cnts + 1):
		if s * i > p:
			continue
		sf = i
		ss = min(f // s, cnts - i)
		fleft = p - sf * s
		sleft = f - ss * s
		wf = min(cntw, fleft // w)
		ws = min(cntw - wf, sleft // w)
		ans = max(sf + ss + wf + ws, ans)
	print(ans)
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	solve(p, f, cnts, cntw, s, w)


t = int(input())
while t:
	t -= 1
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for n1 in range(cs + 1):
		if n1 * s > p:
			break
		n2 = min((p - s * n1) // w, cw)
		cs1 = cs - n1
		cw1 = cw - n2
		(m1, m2) = (0, 0)
		if f > s * cs1:
			m1 = cs1
			m2 = min((f - s * cs1) // w, cw1)
		else:
			m1 = f // s
			m2 = 0
		ans = max(ans, n1 + n2 + m1 + m2)
	print(ans)


import sys
import os
from io import BytesIO, IOBase

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def ddi():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
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 defaultdict
from collections import deque
from math import gcd, pi, inf
from bisect import bisect_left as bl
from bisect import bisect_right as br
for _ in range(ii()):
	(p, f) = mi()
	(cnts, cntw) = mi()
	(s, w) = mi()
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	for i in range(cnts + 1):
		if i * s > p:
			break
		j = min(cntw, (p - i * s) // w)
		u = min(cnts - i, f // s)
		v = min(cntw - j, (f - u * s) // w)
		ans = max(ans, i + j + u + v)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(s, w, cs, cw) = (w, s, cw, cs)
	ans = 0
	for i in range(cs + 1):
		ps = min(i, p // s)
		psr = p - ps * s
		pw = min(cw, psr // w)
		sr = cs - ps
		wr = cw - pw
		fs = min(sr, f // s)
		fsr = f - fs * s
		fw = min(wr, fsr // w)
		ans = max(ans, ps + pw + fs + fw)
	print(ans)


tests = int(input())
for t in range(tests):
	(p, f) = list(map(int, input().split()))
	(cnt_1, cnt_2) = list(map(int, input().split()))
	(cost_1, cost_2) = list(map(int, input().split()))
	if cost_1 > cost_2:
		(cnt_1, cnt_2) = (cnt_2, cnt_1)
		(cost_1, cost_2) = (cost_2, cost_1)
	max_cap_1 = min(p // cost_1, cnt_1)
	curr_max = 0
	for i in range(max_cap_1 + 1):
		p_1 = min(p // cost_1, i)
		p_2 = min((p - p_1 * cost_1) // cost_2, cnt_2)
		f_1 = min(f // cost_1, cnt_1 - p_1)
		f_2 = min((f - f_1 * cost_1) // cost_2, cnt_2 - p_2)
		curr = p_1 + p_2 + f_1 + f_2
		if curr > curr_max:
			curr_max = curr
	print(curr_max)


import math

def pgcd(g1, g2):
	f1 = [1, 0]
	f2 = [0, 1]
	while min(g1, g2) > 0:
		shang1 = g1 // g2
		yu1 = g1 % g2
		f3 = [f1[0] + shang1 * f2[0], f1[1] + shang1 * f2[1]]
		f1 = list(f2)
		f2 = list(f3)
		g1 = g2
		g2 = yu1
	g = g1
	return (g, f1, f2)
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w > s:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	if f > p:
		(p, f) = (f, p)
	rem1 = p
	rem2 = f
	ans = 0
	b = {0: 0, 1: 0}
	(g, f1, f2) = pgcd(s, w)
	rem1 -= rem1 % g
	rem2 -= rem2 % g
	merge = rem1 + rem2
	got = min(merge // w, cntw)
	merge -= got * w
	ans += got
	b[1] += got
	got = min(merge // s, cnts)
	merge -= got * s
	ans += got
	b[0] += got
	fg = True
	for i in range(b[1] + 1):
		if i * w > rem1:
			break
		j = min((rem1 - i * w) // s, b[0])
		if (b[1] - i) * w + (b[0] - j) * s <= rem2:
			fg = False
			break
	if fg:
		ans -= 1
	print(ans)


from math import ceil
t = int(input())
for i in range(t):
	(p, f) = map(int, input().split())
	if p > f:
		(p, f) = (f, p)
	(s, w) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	if cw < cs:
		(cw, cs) = (cs, cw)
		(s, w) = (w, s)
	if p // cs + f // cs <= s:
		print(p // cs + f // cs)
	else:
		a = s
		j = 0
		mb = 0
		while j * cs <= p and j <= a:
			if (a - j) * cs <= f:
				mb = max(mb, min(w, (p - j * cs) // cw + (f - (a - j) * cs) // cw))
			j += 1
		print(a + mb)


for _ in range(int(input())):
	(p, f) = list(map(int, input().split()))
	(cs, cw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if w < s:
		(w, s) = (s, w)
		(cs, cw) = (cw, cs)
	ps = p // s
	fs = f // s
	if ps + fs < cs:
		print(ps + fs)
		continue
	best = 0
	for i in range(cs + 1):
		if p < i * s or f < (cs - i) * s:
			continue
		best = max(best, min(cw, (p - i * s) // w + (f - (cs - i) * s) // w) + cs)
	print(best)


for i in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt1, cnt2) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt1, cnt2) = (cnt2, cnt1)
	idd1 = min(cnt1, p // s)
	idd2 = 0
	p -= s * idd1
	cnt1 -= idd1
	if p >= w:
		idd2 = min(cnt2, p // w)
		cnt2 -= idd2
		p -= w * idd2
	ff = f
	cntt = cnt2
	ans = -1
	while idd1 >= 0:
		f = ff
		if p >= w and cntt > 0:
			p -= w
			cntt -= 1
			idd2 += 1
		cnt11 = cnt1
		idd3 = min(cnt1, f // s)
		f -= s * idd3
		cnttt = cntt
		idd4 = 0
		cnt11 -= idd3
		idd4 = min(cnttt, f // w)
		cnttt -= idd4
		f -= w * idd4
		ans = max(ans, idd1 + idd2 + idd3 + idd4)
		idd1 -= 1
		cnt1 += 1
		p += s
	print(ans)


t = int(input())
for case in range(t):
	(p, f) = list(map(int, input().split()))
	(cnts, cntw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	_max = 0
	for i in range(min(cnts, p // s) + 1):
		result = i
		current_cnts = cnts - i
		usedw = min((p - i * s) // w, cntw)
		result += usedw
		current_cntw = cntw - usedw
		if s <= w:
			useds2 = min(f // s, current_cnts)
			result += useds2
			usedw2 = min((f - useds2 * s) // w, current_cntw)
			result += usedw2
		else:
			usedw2 = min(f // w, current_cntw)
			result += usedw2
			useds2 = min((f - usedw2 * w) // s, current_cnts)
			result += useds2
		if result > _max:
			_max = result
	print(_max)


z = lambda : map(int, input().split())
zz = lambda a, b: (min(a, b), max(a, b))
for _ in range(int(input())):
	(p, f) = z()
	(x, y) = z()
	(s, w) = z()
	(a, b) = zz((s, x), (w, y))
	if p // a[0] + f // a[0] <= a[1]:
		print(p // a[0] + f // a[0])
		continue
	m = 0
	for i in range(a[1] + 1):
		if min(p - i * a[0], f - (a[1] - i) * a[0]) >= 0:
			v = (p - i * a[0]) // b[0] + (f - (a[1] - i) * a[0]) // b[0]
			if v > m:
				m = v
				if m >= b[1]:
					m = b[1]
					break
	print(a[1] + m)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(p, f) = map(int, input().split())
	(ns, na) = map(int, input().split())
	(sw, aw) = map(int, input().split())
	total = 0
	if p < f:
		t = p
		p = f
		f = t
	if sw > aw:
		t = aw
		aw = sw
		sw = t
		t = ns
		ns = na
		na = t
	for i in range(0, ns + 1):
		if i * sw > p:
			continue
		pa = min((p - i * sw) // aw, na)
		fs = min(f // sw, ns - i)
		fa = min((f - fs * sw) // aw, na - pa)
		t = i + pa + fs + fa
		if t > total:
			total = t
	print(total)


for ik in range(int(input())):
	(n, k) = map(int, input().split())
	(ca, cw) = map(int, input().split())
	(s, w1) = map(int, input().split())
	if s > w1:
		(s, w1) = (w1, s)
		(ca, cw) = (cw, ca)
	tot = 0
	lwe = [n, k, ca, cw, s, w1]
	for i in range(ca + 1):
		ans = 0
		(n, k, ca, cw, s, w1) = (lwe[0], lwe[1], lwe[2], lwe[3], lwe[4], lwe[5])
		w = n // s
		if w < i:
			continue
		ans += i
		n -= i * s
		ans += min(cw, n // w1)
		cw -= min(cw, n // w1)
		ca -= i
		ans += min(ca, k // s)
		k -= min(ca, k // s) * s
		ans += min(cw, k // w1)
		tot = max(tot, ans)
	print(tot)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

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

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

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

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

def pick_optimal(cnts, cntw, s, w, p, f):
	answer = 0
	for i in range(1, cnts + 1):
		if i * s > p:
			break
		cnt = i + min(cntw, (p - i * s) // w)
		decw = cntw - min(cntw, (p - i * s) // w)
		decs = cnts - i
		a1 = min(decs, f // s)
		newf = f - min(decs, f // s) * s
		a1 += min(decw, newf // w)
		a2 = min(decw, f // w)
		newf = f - min(decw, f // w) * w
		a2 += min(decs, newf // s)
		cnt += max(a1, a2)
		answer = max(answer, cnt)
	return answer
for _ in range(int(data())):
	(pmain, fmain) = sp()
	(cntsmain, cntwmain) = sp()
	(smain, wmain) = sp()
	result = pick_optimal(cntsmain, cntwmain, smain, wmain, pmain, fmain)
	result = max(result, pick_optimal(cntsmain, cntwmain, smain, wmain, fmain, pmain))
	result = max(result, pick_optimal(cntwmain, cntsmain, wmain, smain, pmain, fmain))
	result = max(result, pick_optimal(cntwmain, cntsmain, wmain, smain, fmain, pmain))
	out(result)


def maximize_items_count(p, f, cnt_s, cnt_w, s, w):
	if s > w or (s == w and cnt_s < cnt_w):
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
		(s, w) = (w, s)
	max_sum = 0
	max_cnt_s = min(cnt_s, p // s + f // s)
	p_cnt_s = 0
	while p_cnt_s <= max_cnt_s:
		p_cnt_w = (p - s * p_cnt_s) // w
		f_cnt_w = (f - s * (max_cnt_s - p_cnt_s)) // w
		if p_cnt_w >= 0 and f_cnt_w >= 0:
			max_sum = max(max_sum, max_cnt_s + min(cnt_w, p_cnt_w + f_cnt_w))
		p_cnt_s += 1
	return max_sum
t = int(input())
for i in range(t):
	(p, f) = list(map(int, input().split()))
	(cnt_s, cnt_w) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	print(maximize_items_count(p, f, cnt_s, cnt_w, s, w))


t = int(input())
for _ in range(t):
	(p, f) = [int(s) for s in input().split(' ')]
	(cnt_s, cnt_w) = [int(s) for s in input().split(' ')]
	(s, w) = [int(s) for s in input().split(' ')]
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	ans = 0
	for s1 in range(min(p // s, cnt_s) + 1):
		w1 = min(cnt_w, (p - s1 * s) // w)
		s2 = min(cnt_s - s1, f // s)
		w2 = min(cnt_w - w1, (f - s2 * s) // w)
		ans = max(ans, s1 + w1 + s2 + w2)
	print(ans)


tests = int(input())
for t in range(tests):
	(p, f) = list(map(int, input().split()))
	(cnt_1, cnt_2) = list(map(int, input().split()))
	(cost_1, cost_2) = list(map(int, input().split()))
	if cost_1 > cost_2:
		(cnt_1, cnt_2) = (cnt_2, cnt_1)
		(cost_1, cost_2) = (cost_2, cost_1)
	max_cap_1 = p // cost_1 + f // cost_1
	if max_cap_1 <= cnt_1:
		print(max_cap_1)
	else:
		check = True
		if p // cost_1 >= cnt_1:
			p_1 = cnt_1
			if (p - p_1 * cost_1) // cost_2 >= cnt_2:
				print(cnt_1 + cnt_2)
				check = False
			else:
				p_2 = (p - p_1 * cost_1) // cost_2
				f_1 = 0
				if f // cost_2 >= cnt_2 - p_2:
					print(cnt_1 + cnt_2)
					check = False
				else:
					f_2 = f // cost_2
		else:
			p_1 = p // cost_1
			p_2 = 0
			if (cnt_1 - p_1) * cost_1 >= f:
				print(p_1 + f // cost_1)
				check = False
			else:
				f_1 = cnt_1 - p_1
				if (f - f_1 * cost_1) // cost_2 >= cnt_2:
					print(cnt_1 + cnt_2)
					check = False
				else:
					f_2 = (f - f_1 * cost_1) // cost_2
		if check:
			p_s = [p_1, p_2, p - p_1 * cost_1 - p_2 * cost_2]
			f_s = [f_1, f_2, f - f_1 * cost_1 - f_2 * cost_2]
			curr_max = p_1 + p_2 + f_1 + f_2
			for i in range(p_1):
				p_s[0] -= 1
				p_s[2] += cost_1
				if p_s[2] >= cost_2:
					p_s[2] -= cost_2
					p_s[1] += 1
				f_s[0] += 1
				f_s[2] -= cost_1
				if f_s[2] < 0:
					if f_s[1] == 0:
						break
					else:
						f_s[1] -= 1
						f_s[2] += cost_2
				curr = p_s[0] + p_s[1] + f_s[0] + f_s[1]
				if curr > curr_max:
					curr_max = curr
			print(curr_max)


for _ in range(int(input())):
	(p, f) = (int(i) for i in input().split())
	(cnt_s, cnt_w) = (int(i) for i in input().split())
	(s, w) = (int(i) for i in input().split())
	if w < s:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	cap_lowest = p // s + f // s
	if cap_lowest <= cnt_s:
		print(cap_lowest)
	else:
		cap_highest = 0
		for (p_rest, f_rest) in ((p - i * s, f - (cnt_s - i) * s) for i in range(cnt_s + 1)):
			if p_rest < 0 or f_rest < 0:
				continue
			cap_highest = max(cap_highest, p_rest // w + f_rest // w)
		print(cnt_s + min(cnt_w, cap_highest))


def can_do_one_more(p, f, ns, nw, s, w):
	for fw in range(nw + 1):
		if fw * w > f:
			continue
		fs = (f - fw * w) // s
		ps = ns - fs
		pw = nw - fw
		if ps < 0 or pw < 0 or fs < 0 or (fw < 0):
			continue
		if ps * s + pw * w <= p and fs * s + fw * w <= f:
			return True
	return False

def solve(p, f, cs, cw, s, w):
	op = p
	of = f
	fs = min(f // s, cs)
	f -= fs * s
	cs -= fs
	ps = min(p // s, cs)
	p -= ps * s
	cs -= ps
	fw = min(f // w, cw)
	f -= fw * f
	cw -= fw
	pw = min(p // w, cw)
	p -= pw * w
	cw -= pw
	total = ps + pw + fs + fw
	if cs or not cw:
		return total
	return total + can_do_one_more(op, of, ps + fs, pw + fw + 1, s, w)

def main():
	t = int(input())
	for _ in range(t):
		(p, f) = sorted(list(map(int, input().split())), reverse=True)
		(cs, cw) = map(int, input().split())
		(s, w) = map(int, input().split())
		if w < s:
			(s, w) = (w, s)
			(cs, cw) = (cw, cs)
		print(solve(p, f, cs, cw, s, w))
main()


import math
from collections import deque
import sys
sys.setrecursionlimit(10 ** 4)

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

def SieveOfEratosthenes(n):
	l = []
	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
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

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

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < abs(max_ending_here):
			max_so_far = max_ending_here
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	(p, f) = list(map(int, input().split()))
	(cnts, cntw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	ans = 0
	if s > w:
		t1 = s
		s = w
		w = t1
		t1 = cnts
		cnts = cntw
		cntw = t1
	for s1 in range(0, min(cnts, p // s) + 1):
		w1 = min(cntw, (p - s1 * s) // w)
		s2 = min(cnts - s1, f // s)
		w2 = min(cntw - w1, (f - s2 * s) // w)
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)
t = int(input())
for i in range(0, t):
	main()


n = int(input())
for i in range(n):
	(play1, play2) = map(int, input().split())
	(count1, count2) = map(int, input().split())
	(x, y) = map(int, input().split())
	l = 0
	(x1, y1, x2, y2) = (0, 0, 0, 0)
	ans = 0
	if x > y:
		(x, y) = (y, x)
		(count1, count2) = (count2, count1)
	n1 = play1 // x
	for i in range(min(n1, count1), -1, -1):
		left = play1 - i * x
		y1 = min(left // y, count2)
		s = i + y1
		x2 = min(play2 // x, count1 - i)
		y2 = min((play2 - x2 * x) // y, count2 - y1)
		s += x2 + y2
		ans = max(ans, s)
	print(ans)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
from functools import lru_cache

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 Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	p = 0
	f = 0
	cp2 = 0
	cp1 = 0
	wf = 0
	wp = 0
	(p, f) = ilele()
	(cp1, cp2) = ilele()
	(wp, wf) = ilele()
	ans = 0
	for i in range(cp1 + 1):
		c1 = cp2
		c2 = cp1
		(p1, p2, wa) = (0, 0, 0)
		if p >= wp * i:
			wa = i + min(c1, (p - wp * i) // wf)
			c1 -= min(c1, (p - wp * i) // wf)
			c2 -= i
		p1 = min(c2, f // wp) + min(c1, (f - min(c2, f // wp) * wp) // wf)
		p2 = min(c1, f // wf) + min(c2, (f - min(c1, f // wf) * wf) // wp)
		wa += max(p2, p1)
		ans = max(wa, ans)
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		max_weights = _read_ints()
		items_amounts = _read_ints()
		items_weights = _read_ints()
		result = compute_max_ingots_n(max_weights, items_amounts, items_weights)
		print(result)

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

def compute_max_ingots_n(max_weights, items_amounts, items_weights):
	(max_weight_1, max_weight_2) = max_weights
	(a_max_n, b_max_n) = items_amounts
	(a_weight, b_weight) = items_weights
	get_b1_n_by_a1_n = lambda a_n: min((max_weight_1 - a_n * a_weight) // b_weight, b_max_n)
	sets_1_variants = [(a_n, get_b1_n_by_a1_n(a_n)) for a_n in range(0, min(a_max_n + 1, max_weight_1 // a_weight + 1))]
	sets_2_variants = [_find_best_items_set(max_weight_2, (a_max_n - a1_n, b_max_n - b1_n), (a_weight, b_weight)) for (a1_n, b1_n) in sets_1_variants]
	return max((a1 + b1 + a2 + b2 for ((a1, b1), (a2, b2)) in zip(sets_1_variants, sets_2_variants)))

def _find_best_items_set(max_weight, items_amounts, items_weights):
	(max_a, max_b) = items_amounts
	(x, y) = items_weights
	if not x <= y:
		(x, y) = (y, x)
		(max_a, max_b) = (max_b, max_a)
	z = max_weight
	selected_a = min(max_a, z // x)
	if max_b == 0:
		return (selected_a, 0)
	remain_for_b = z - x * selected_a
	if remain_for_b // y > 0:
		selected_b = min(remain_for_b // y, max_b)
		result = _find_best_items_set(z - selected_b * y, (max_a, max_b - selected_b), (x, y))
		result = list(result)
		result[1] += selected_b
		return tuple(result)
	if x == y:
		return (selected_a, 0)
	remain = z - selected_a * x
	free_up = _how_many_should_free_up(remain, x, y, max_b)
	selected_a -= free_up
	remain = z - selected_a * x
	selected_b = remain // y
	selected_b = min(selected_b, max_b)
	return (selected_a, selected_b)

def _how_many_should_free_up(remain, lower_weight, higher_weight, max_higher_weight_n):
	r = remain
	a = lower_weight
	b = higher_weight
	b_lim = max_higher_weight_n
	assert r < b
	x = min((r - b) // (b - a), (b_lim * b + b - 1 - r) // a)
	x = max(x, 0)
	return x
main()


t = int(input())
for i in range(t):
	(p, f) = list(map(int, input().split()))
	(c1, c2) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if s <= w:
		a = min(c1, p // s)
		ans = 0
		for s1 in range(a + 1):
			s2 = min(c1 - s1, f // s)
			w1 = min(c2, (p - s1 * s) // w)
			w2 = min(c2 - w1, (f - s * s2) // w)
			ans = max(ans, s1 + s2 + w1 + w2)
		print(ans)
	else:
		b = min(c2, p // w)
		ans = 0
		for w1 in range(b + 1):
			w2 = min(c2 - w1, f // w)
			s1 = min(c1, (p - w * w1) // s)
			s2 = min(c1 - s1, (f - w * w2) // s)
			ans = max(ans, w1 + w2 + s1 + s2)
		print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	if p // s + f // s <= cs:
		print(p // s + f // s)
	else:
		ans = 0
		for i in range(cs + 1):
			if s * i <= p and s * (cs - i) <= f:
				a = p - s * i
				b = f - s * (cs - i)
				ans = max(ans, cs + min(cw, a // w + b // w))
		print(ans)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	(p, f) = MI()
	(cs, cw) = MI()
	(s, w) = MI()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		if i * s > p:
			break
		pw = (p - i * s) // w
		fs = min(cs - i, f // s)
		fw = min((f - fs * s) // w, cw - pw)
		cur = i + pw + fs + fw
		ans = max(ans, cur)
	print(ans)


n = int(input())
for _ in range(n):
	(capi, capj) = list(map(int, input().split()))
	(lcnt, hcnt) = list(map(int, input().split()))
	(lw, hw) = list(map(int, input().split()))
	if lw > hw:
		(lw, hw) = (hw, lw)
		(lcnt, hcnt) = (hcnt, lcnt)
	ans = 0
	for i in range(lcnt + 1):
		j = lcnt - i
		qli = min(capi // lw, i)
		qlj = min(capj // lw, j)
		resi = capi - qli * lw
		resj = capj - qlj * lw
		qhi = resi // hw
		qhj = resj // hw
		qh = min(hcnt, qhi + qhj)
		ans = max(ans, qli + qlj + qh)
	print(ans)


t = int(input().split()[0])
for case in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	fwmax = min(p // w, cntw)
	for fw in range(fwmax + 1):
		fs = min(cnts, (p - fw * w) // s)
		news = cnts - fs
		neww = cntw - fw
		ss = min(news, f // s)
		sw = min(neww, (f - ss * s) // w)
		if fs + fw + ss + sw > ans:
			ans = fs + fw + ss + sw
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(cnts, cntw) = (cntw, cnts)
		(s, w) = (w, s)
	for i in range(cnts + 1):
		if p >= i * s:
			pp = p - i * s
			j = min(f // s, cnts - i)
			ff = f - j * s
			cnt = i + j
			pp = pp // w
			ff = ff // w
			cnt += min(cntw, pp + ff)
			ans = max(ans, cnt)
		else:
			break
	print(ans)


rr = lambda : input().strip()
rrm = lambda : map(int, rr().split())

def solve():
	(p, f) = rrm()
	(scnt, wcnt) = rrm()
	(s, w) = rrm()
	ans = 0
	if w < s:
		(s, w) = (w, s)
		(wcnt, scnt) = (scnt, wcnt)
	x = min(scnt, p // s)
	for s1 in range(x + 1):
		w1 = min(wcnt, (p - s1 * s) // w)
		s2 = min(scnt - s1, f // s)
		w2 = min(wcnt - w1, (f - s2 * s) // w)
		ans = max(ans, s1 + s2 + w1 + w2)
	return ans
T = int(rr())
for _ in range(T):
	ans = solve()
	print(ans)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	(p, f) = list(map(int, stdin.readline().split()))
	(cs, cw) = list(map(int, stdin.readline().split()))
	(s, w) = list(map(int, stdin.readline().split()))
	a = [(s, cs), (w, cw)]
	a.sort()
	mn = a[0][0]
	mx = a[1][0]
	cmn = a[0][1]
	cmx = a[1][1]
	ans = 0
	for i in range(0, cmn + 1, 1):
		tmn = cmn
		tmx = cmx
		tp = p
		tf = f
		if p < i * mn:
			break
		tmp = i
		tp -= i * mn
		tmn -= i
		rem = min(tmx, tp // mx)
		tmp += rem
		tmx -= rem
		mnfil = min(tmn, tf // mn)
		tmp += mnfil
		tf -= mnfil * mn
		mxfil = min(tmx, tf // mx)
		tmp += mxfil
		ans = max(ans, tmp)
	print(ans)


def solve(a, b, c, d, e, f) -> int:
	ans = 0
	for j in range(0, min(c, a // e) + 1):
		ans1 = j
		ans2 = min((a - ans1 * e) // f, d)
		ans3 = min(c - ans1, b // e)
		ans4 = min((b - ans3 * e) // f, d - ans2)
		ans = max(ans, ans1 + ans2 + ans3 + ans4)
	return ans
t = int(input())
for i in range(t):
	(p, f) = [int(x) for x in input().split()]
	(cs, cw) = [int(x) for x in input().split()]
	(s, w) = [int(x) for x in input().split()]
	if s < w:
		if p < f:
			print(solve(f, p, cs, cw, s, w))
		else:
			print(solve(p, f, cs, cw, s, w))
	elif p < f:
		print(solve(f, p, cw, cs, w, s))
	else:
		print(solve(p, f, cw, cs, w, s))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	(maxa, mina) = (max(p, f), min(p, f))
	(maxa1, mina1) = (maxa, mina)
	l = [[s, cs], [w, cw]]
	l.sort()
	l1 = []
	for i in l:
		xy = i[:]
		l1.append(xy)
	ans = 0
	for i in range(l[0][1]):
		if (i + 1) * l[0][0] <= mina:
			one = i + 1
			left = mina - one * l[0][0]
			two = min(left // l[1][0], l[1][1])
			tmp1 = l[0][1] - one
			tmp2 = l[1][1] - two
			three = min(maxa // l[0][0], tmp1)
			left = maxa - three * l[0][0]
			four = min(left // l[1][0], tmp2)
			ans = max(ans, one + two + three + four)
	for i in range(l[0][1]):
		if (i + 1) * l[0][0] <= maxa1:
			one = i + 1
			left = maxa1 - one * l1[0][0]
			two = min(left // l1[1][0], l1[1][1])
			tmp1 = l1[0][1] - one
			tmp2 = l1[1][1] - two
			three = min(mina1 // l1[0][0], tmp1)
			left = mina1 - three * l1[0][0]
			four = min(left // l1[1][0], tmp2)
			ans = max(ans, one + two + three + four)
	sys.stdout.write(str(ans) + '\n')


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	(p, f) = (max(p, f), min(p, f))
	if w < s:
		(w, s) = (s, w)
		(cw, cs) = (cs, cw)
	ns = min(p // s, cs)
	ans = 0
	for i in range(0, ns + 1):
		s1 = i
		s2 = min(f // s, cs - i)
		w1 = min((p - s1 * s) // w, cw)
		w2 = min(cw - w1, (f - s2 * s) // w)
		res = s1 + w1 + s2 + w2
		ans = max(ans, res)
	print(ans)


def solve():
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		if s * i > p:
			break
		j = min((p - s * i) // w, cntw)
		u = min(cnts - i, f // s)
		v = min(cntw - j, (f - s * u) // w)
		ans = max(ans, i + j + u + v)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


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):
		(p, f) = LI()
		(cs, cw) = LI()
		(s, w) = LI()
		if s > w:
			(s, w) = (w, s)
			(cs, cw) = (cw, cs)

		def ff(i):
			r = i
			t = p - i * s
			u = min(cw, t // w)
			r += u
			j = min(cs - i, f // s)
			r += j
			r += min(cw - u, (f - j * s) // w)
			return r
		r = 0
		for i in range(min(cs, p // s) + 1):
			t = ff(i)
			if r < t:
				r = t
		rr.append(r)
	return JA(rr, '\n')
print(main())


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(p, f) = list(map(int, stdin.readline().split()))
	(cs, cw) = list(map(int, stdin.readline().split()))
	(s, w) = list(map(int, stdin.readline().split()))
	if s > w:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	ans = 0
	for ps in range(cs + 1):
		if ps * s > p:
			break
		pw = min(cw, (p - ps * s) // w)
		fs = min(cs - ps, f // s)
		fw = min(cw - pw, (f - fs * s) // w)
		ans = max(ans, ps + pw + fs + fw)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cw + 1):
		if i * w > p:
			break
		j = min(cs, (p - i * w) // s)
		if (cs - j) * s >= f:
			ans = max(ans, i + j + f // s)
		else:
			ans = max(ans, cs + i + min(cw - i, (f - (cs - j) * s) // w))
	print(ans)


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	(p, f) = map(int, input().split())
	(ns, na) = map(int, input().split())
	(s, a) = map(int, input().split())
	wynik = 0
	for ps in range(ns + 1):
		if ps * s > p:
			continue
		pa = (p - ps * s) // a
		pa = min(pa, na)
		pozs = ns - ps
		poza = na - pa
		if s > a:
			fa = f // a
			fa = min(fa, poza)
			fs = (f - fa * a) // s
			fs = min(fs, pozs)
		else:
			fs = f // s
			fs = min(fs, pozs)
			fa = (f - fs * s) // a
			fa = min(fa, poza)
		wynik = max(wynik, fa + fs + pa + ps)
	print(wynik)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(ss, ww) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	ma = 0
	if c1 > c2:
		(ss, ww) = (ww, ss)
		(c1, c2) = (c2, c1)
	for i in range(ss + 1):
		pss = min(i, p // c1)
		pww = min(ww, (p - pss * c1) // c2)
		fss = min(ss - pss, f // c1)
		fww = min(ww - pww, (f - fss * c1) // c2)
		ma = max(ma, pss + pww + fss + fww)
	print(ma)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	(p, f) = map(int, ip().split())
	(cnts, cntw) = map(int, ip().split())
	(s, w) = map(int, ip().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for sp in range(min(cnts, p // s) + 1):
		wp = min(cntw, (p - sp * s) // w)
		sf = min(cnts - sp, f // s)
		wf = min(cntw - wp, (f - sf * s) // w)
		ans = max(sp + wp + sf + wf, ans)
	print(ans)


gans = []
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(n, m) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(n, m) = (m, n)
	ans = 0
	for i in range(min(n, p // s) + 1):
		j = min(n - i, f // s)
		p1 = p - i * s
		f1 = f - j * s
		ansi = i + j + min(f1 // w + p1 // w, m)
		ans = max(ans, ansi)
	gans.append(ans)
print('\n'.join(map(str, gans)))


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())

	def can_take(s, w, cs, cw):
		if s > w:
			return can_take(w, s, cw, cs)
		if s * cs >= f:
			return f // s
		return cs + min((f - s * cs) // w, cw)
	ans = 0
	for i in range(cs + 1):
		w_of_s = i * s
		if w_of_s <= p:
			tw = min((p - w_of_s) // w, cw)
			ans = max(ans, i + tw + can_take(s, w, cs - i, cw - tw))
	print(ans)


import sys

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 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(F, P) = MAP()
	(N, M) = MAP()
	(s, w) = MAP()
	if s > w:
		(s, w) = (w, s)
		(N, M) = (M, N)
	ans = 0
	for i in range(N + 1):
		cnt = 0
		(f, p) = (F, P)
		(cs, cw) = (N, M)
		use = min(f // s, i)
		f -= use * s
		cs -= use
		cnt += use
		use = min(p // s, N - i)
		p -= use * s
		cs -= use
		cnt += use
		use = min(f // w, cw)
		f -= use * w
		cw -= use
		cnt += use
		use = min(p // w, cw)
		p -= use * w
		cw -= use
		cnt += use
		ans = max(ans, cnt)
	print(ans)


from sys import *
from math import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	(cnt1, cnt2) = map(int, stdin.readline().split())
	(s, w) = map(int, stdin.readline().split())
	if s > w:
		(s, w) = (w, s)
		(cnt1, cnt2) = (cnt2, cnt1)
	ans = 0
	for i in range(min(n // s, cnt1) + 1):
		x = min((n - i * s) // w, cnt2)
		y = min(k // s, cnt1 - i)
		z = min((k - y * s) // w, cnt2 - x)
		ans = max(ans, i + x + y + z)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = []
	for i in range(min(cs, p // s) + 1):
		j = min(cw, (p - i * s) // w)
		k = min(cs - i, f // s)
		l = min(cw - j, (f - k * s) // w)
		ans.append(i + j + k + l)
	print(max(ans))


def solve():
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	mans = 0
	for i in range(cnts + 1):
		ans = 0
		if p >= s * i:
			ans += i
			cntsnow = cnts - i
			pnow = p - s * i
			ans += min(cntw, pnow // w)
			cntwnow = cntw - min(cntw, pnow // w)
		fn = f
		ans += min(fn // s, cntsnow)
		fn -= min(fn // s, cntsnow) * s
		ans += min(fn // w, cntwnow)
		mans = max(ans, mans)
	print(mans)
for i in range(int(input())):
	solve()


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(scount, wcount) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(scount, wcount) = (wcount, scount)
	for i in range(scount + 1):
		if i * s > p:
			break
		j = (p - i * s) // w
		k = min(scount - i, f // s)
		l = min((f - k * s) // w, wcount - j)
		ans = max(ans, i + j + l + k)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cntw, cnts) = (cnts, cntw)
	kek = p // s + f // s
	if kek <= cnts:
		print(kek)
	else:
		ans = cnts
		for sk in range(cnts + 1):
			(p2, f2) = (p, f)
			p2 -= sk * s
			f2 -= (cnts - sk) * s
			if p2 >= 0 and f2 >= 0:
				ans = max(ans, cnts + p2 // w + f2 // w)
		ans = min(ans, cnts + cntw)
		print(ans)


import sys
input = sys.stdin.readline

def answer(x, y, f, s, w):
	total = 0
	g1 = min(f // s, x)
	total += g1
	q = f - g1 * s
	g1 = min(q // w, y)
	total += g1
	return total
a = int(input())
for i in range(a):
	(p, f) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(c1, c2) = (c2, c1)
	maxa = 0
	for i in range(c1 + 1):
		if i * s > p:
			break
		total = 0
		total += i
		q = p - i * s
		pot = min(q // w, c2)
		total += pot
		q -= pot * w
		total += answer(c1 - i, c2 - pot, f, s, w)
		maxa = max(maxa, total)
	print(maxa)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq 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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

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()):
	(p, f) = sorted(value(), reverse=True)
	(c1, c2) = value()
	(w1, w2) = value()
	if w1 > w2:
		(c1, c2) = (c2, c1)
		(w1, w2) = (w2, w1)
	ans = 0
	Range = min(c1, p // w1)
	for p1 in range(Range + 1):
		rem_p = p - p1 * w1
		p2 = min(rem_p // w2, c2)
		f1 = min(f // w1, c1 - p1)
		rem_f = f - f1 * w1
		f2 = min(rem_f // w2, c2 - p2)
		ans = max(ans, p1 + p2 + f1 + f2)
	(p, f) = (f, p)
	Range = min(c1, p // w1)
	for p1 in range(Range + 1):
		rem_p = p - p1 * w1
		p2 = min(rem_p // w2, c2)
		f1 = min(f // w1, c1 - p1)
		rem_f = f - f1 * w1
		f2 = min(rem_f // w2, c2 - p2)
		ans = max(ans, p1 + p2 + f1 + f2)
	print(ans)


def solve2(p1, p2, cnt1, cnt2, w1, w2):
	ans = 0
	ans += min(p1 // w2, cnt2)
	cnt2 -= ans
	carry = min(p2 // w1, cnt1)
	ans += carry
	cnt1 -= carry
	p2 -= carry * w1
	carry = min(p2 // w2, cnt2)
	ans += carry
	return ans

def solve(p1, p2, cnt1, cnt2, w1, w2):
	ans = 0
	for i in range(cnt1 + 1):
		if i * w1 > p1:
			break
		cur_ans = i + solve2(p1 - i * w1, p2, cnt1 - i, cnt2, w1, w2)
		ans = max(ans, cur_ans)
	return ans
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	print(solve(p, f, cnt_s, cnt_w, s, w))


t = int(input())
for _ in range(t):
	[p1, p2] = list(map(int, input().split()))
	cnt = list(map(int, input().split()))
	w = list(map(int, input().split()))
	tot = sum(cnt)
	MIN = -1
	if w[0] < w[1]:
		MIN = 0
	else:
		MIN = 1
	MAX = int(not MIN)
	max1 = p1 // w[MIN]
	max2 = p2 // w[MIN]
	maxpos = max1 + max2
	if cnt[MIN] >= maxpos:
		print(maxpos)
	else:
		maximum = -1
		for i in range(0, min(cnt[MIN] + 1, max1 + 1)):
			i2 = cnt[MIN] - i
			if i2 <= max2:
				j1 = min((p1 - i * w[MIN]) // w[MAX], cnt[MAX])
				j2 = min((p2 - i2 * w[MIN]) // w[MAX], cnt[MAX] - j1)
				final = i + i2 + j1 + j2
				if final > maximum:
					maximum = final
		print(maximum)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	(p, f) = MI()
	(cs, cw) = MI()
	(s, w) = MI()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	(s1, ans) = (0, 0)
	while s1 <= cs and s1 * s <= p:
		w1 = min(cw, (p - s1 * s) // w)
		s2 = min(cs - s1, f // s)
		w2 = min(cw - w1, (f - s2 * s) // w)
		ans = max(ans, s1 + w1 + s2 + w2)
		s1 += 1
	print(ans)


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s >= w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		if i * s > p:
			break
		t = cw
		add = min(cw, (p - i * s) // w)
		t -= add
		if (cs - i) * s >= f:
			ans = max(ans, i + add + f // s)
		else:
			ans = max(ans, i + add + cs - i + min(t, (f - (cs - i) * s) // w))
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = [int(i) for i in input().split()]
	(cnt_s, cnt_w) = [int(i) for i in input().split()]
	(s, w) = [int(i) for i in input().split()]
	if s < w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	max_w = p // w + f // w
	if max_w <= cnt_w:
		print(max_w)
		continue
	max_s = 0
	for w_p in range(cnt_w - min(cnt_w, f // w), min(cnt_w, p // w) + 1):
		p_left = p - w * w_p
		f_left = f - w * (cnt_w - w_p)
		max_s = max(max_s, p_left // s + f_left // s)
	print(cnt_w + min(cnt_s, max_s))


def answer(p, f, cs, cw, s, w):
	if max(p, f) >= cs * s + cw * w:
		return cs + cw
	elif max(p, f) < min(s, w):
		return 0
	elif s > w:
		if p // w + f // w > cw:
			maxi = 0
			for i in range(0, cw + 1):
				count = 0
				if p - i * w >= 0:
					if f - (cw - i) * w >= 0:
						count += cw
						x = (p - i * w) // s + (f - (cw - i) * w) // s
						if x >= cs:
							count += cs
						else:
							count += x
				else:
					break
				maxi = max(maxi, count)
			return maxi
		else:
			return p // w + f // w
	elif p // s + f // s > cs:
		maxi = 0
		for i in range(0, cs + 1):
			count = 0
			if p - i * s >= 0:
				if f - (cs - i) * s >= 0:
					count += cs
					x = (p - i * s) // w + (f - (cs - i) * s) // w
					if x >= cw:
						count += cw
					else:
						count += x
			else:
				break
			maxi = max(maxi, count)
		return maxi
	else:
		return p // s + f // s
t = int(input())
for i in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	print(answer(p, f, cs, cw, s, w))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(p, f) = list(map(int, input().split()))
		(c1, c2) = list(map(int, input().split()))
		(w1, w2) = list(map(int, input().split()))
		if w1 > w2:
			(w1, w2) = (w2, w1)
			(c1, c2) = (c2, c1)
		elif w1 == w2:
			if c1 < c2:
				(c1, c2) = (c2, c1)
		len1 = min(p // w1, c1)
		ans = 0
		for i in range(len1 + 1):
			currans = i + min((p - w1 * i) // w2, c2) + min(f // w1, c1 - i) + min((f - min(f // w1, c1 - i) * w1) // w2, c2 - min((p - w1 * i) // w2, c2))
			ans = max(ans, currans)
		yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
while t:
	t = t - 1
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		temp = s
		s = w
		w = temp
		temp = cnts
		cnts = cntw
		cntw = temp
	cnt = 0
	for i in range(cnts + 1):
		if i * s > p:
			continue
		sf = i
		ss = min(f // s, cnts - i)
		left_f = p - sf * s
		left_s = f - ss * s
		wf = min(cntw, left_f // w)
		ws = min(cntw - wf, left_s // w)
		cnt = max(cnt, sf + ss + wf + ws)
	print(cnt)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	scount = min(p // s, cnts)
	ans = 0
	for i in range(scount + 1):
		tempP = p - i * s
		temp = i + min(tempP // w, cntw)
		tempcntS = cnts - i
		tempcntW = cntw - min(cntw, tempP // w)
		if s < w:
			temp += min(tempcntS, f // s)
			tempF = f - min(tempcntS, f // s) * s
			temp += min(tempcntW, tempF // w)
			ans = max(ans, temp)
		else:
			temp += min(tempcntW, f // w)
			tempF = f - min(tempcntW, f // w) * w
			temp += min(tempcntS, tempF // s)
			ans = max(ans, temp)
	print(ans)


t = int(input())
for you in range(t):
	l = input().split()
	p = int(l[0])
	f = int(l[1])
	l = input().split()
	cnts = int(l[0])
	cntw = int(l[1])
	l = input().split()
	s = int(l[0])
	w = int(l[1])
	maxa = []
	if s > w:
		(w, s) = (s, w)
		(cnts, cntw) = (cntw, cnts)
	for i in range(cnts + 1):
		remp = p - i * s
		if remp < 0:
			break
		z = i + min(remp // w, cntw)
		remsw = cnts - i
		remax = cntw - min(remp // w, cntw)
		my = f
		z += min(my // s, remsw)
		my -= s * min(my // s, remsw)
		z += min(my // w, remax)
		maxa.append(z)
	print(max(maxa))


for t in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s < w:
		bw = [s, cs]
		ww = [w, cw]
	else:
		bw = [w, cw]
		ww = [s, cs]
	tot = p + f
	hmb = min(tot // bw[0], bw[1])
	tot -= hmb * bw[0]
	hmw = min(tot // ww[0], ww[1])
	tot -= hmw * ww[0]
	ans = hmb + hmw - 1
	for i in range(hmb + 1):
		me = [i, (p - i * bw[0]) // ww[0]]
		pt = [hmb - i, (f - (hmb - i) * bw[0]) // ww[0]]
		if me[1] >= 0 and pt[1] >= 0 and (me[1] + pt[1] >= hmw):
			ans += 1
			break
	print(ans)


import sys
input = sys.stdin.readline
for kek in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s >= w:
		(s, w) = (w, s)
		(cnt_w, cnt_s) = (cnt_s, cnt_w)
	ma_s = min(cnt_s, p // s + f // s)
	ma_w = 0
	for i in range(ma_s + 1):
		zz = 0
		if p - i * s >= 0:
			zz += (p - i * s) // w
		else:
			continue
		if f - (ma_s - i) * s >= 0:
			zz += (f - (ma_s - i) * s) // w
		else:
			continue
		ma_w = max(ma_w, zz)
	print(min(ma_w, cnt_w) + ma_s)


t = int(input())
for _ in range(t):
	(p, f) = list(map(int, input().split()))
	(cnt1, cnt2) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if s > w:
		temp = s
		s = w
		w = temp
		temp = cnt1
		cnt1 = cnt2
		cnt2 = temp
	t1 = 0
	for i in range(cnt1 + 1):
		if i * s > p:
			continue
		else:
			l2 = min(f // s, cnt1 - i)
			l1 = p - i * s
			l3 = f - l2 * s
			m1 = min(l1 // w, cnt2)
			m2 = min(l3 // w, cnt2 - m1)
			t1 = max(t1, m1 + m2 + i + l2)
	print(t1)


from math import inf
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(a, b) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(s, w) = (w, s)
		(a, b) = (b, a)
	S = min(a, p // s)
	mini = 0
	for x1 in range(S + 1):
		y1 = min(b, (p - x1 * s) // w)
		x2 = min(a - x1, f // s)
		y2 = min(b - y1, (f - s * x2) // w)
		mini = max(mini, x1 + y1 + x2 + y2)
	print(mini)


import sys
input = sys.stdin.buffer.readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
_T_ = inin()
for _t_ in range(_T_):
	(p, f) = inar()
	(cs, cw) = inar()
	(s, w) = inar()
	if w < s:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(0, cs + 1):
		itakes = min(p // s, i)
		itakew = min(cw, (p - itakes * s) // w)
		ftakes = min(cs - itakes, f // s)
		ftakew = min(cw - itakew, (f - ftakes * s) // w)
		ans = max(ans, itakes + itakew + ftakes + ftakew)
	print(ans)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	(p, f) = map(int, input().split())
	(s, w) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	ans = 0
	if cs > cw:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	for s1 in range(0, min(s, p // cs) + 1):
		w1 = min(w, (p - cs * s1) // cw)
		s2 = min(s - s1, f // cs)
		w2 = min(w - w1, (f - cs * s2) // cw)
		ans = max(ans, s1 + s2 + w1 + w2)
	print(ans)
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	(player1_capacity, player2_capacity) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	objects = [(s, cnt_s), (w, cnt_w)]
	objects.sort()
	(lighter_weight, lighter_quantity) = objects[0]
	(heavier_weight, heavier_quantity) = objects[1]
	most_weapons = 0
	for player1_light in range(lighter_quantity + 1):
		if player1_light * lighter_weight > player1_capacity:
			break
		player1_heavy = (player1_capacity - player1_light * lighter_weight) // heavier_weight
		player1_heavy = min(player1_heavy, heavier_quantity)
		player2_light = min(lighter_quantity - player1_light, player2_capacity // lighter_weight)
		player2_heavy = (player2_capacity - player2_light * lighter_weight) // heavier_weight
		player2_heavy = min(heavier_quantity - player1_heavy, player2_heavy)
		total_weapons = player1_light + player1_heavy + player2_light + player2_heavy
		most_weapons = max(most_weapons, total_weapons)
	print(most_weapons)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		if i <= p // s:
			(pp, ff) = (p, f)
			pp -= s * i
			ok = min(f // s, cs - i)
			ret = ok + i
			ff -= s * ok
			ret += min(cw, pp // w + ff // w)
			ans = max(ans, ret)
	print(int(ans))


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	answer = 0
	for i in range(cnts + 1):
		if i * s > p:
			break
		temp1 = i
		temp2 = min(cntw, (p - i * s) // w)
		t_cnts = cnts - i
		t_cntw = cntw - temp2
		if s < w:
			temp3 = min(t_cnts, f // s)
			temp4 = min(t_cntw, (f - temp3 * s) // w)
			answer = max(answer, temp1 + temp2 + temp3 + temp4)
		else:
			temp3 = min(t_cntw, f // w)
			temp4 = min(t_cnts, (f - temp3 * w) // s)
			answer = max(answer, temp1 + temp2 + temp3 + temp4)
	print(answer)


def main():
	for _ in range(Iint()):
		(myCapacity, friendCapcity) = Ilist()
		(countSword, countWarAxe) = Ilist()
		(SwordWeight, WarAxeWeight) = Ilist()
		if SwordWeight > WarAxeWeight:
			(SwordWeight, WarAxeWeight) = (WarAxeWeight, SwordWeight)
			(countSword, countWarAxe) = (countWarAxe, countSword)
		TotalCount = myCapacity // SwordWeight + friendCapcity // SwordWeight
		if TotalCount <= countSword:
			print(TotalCount)
			continue
		else:
			TotalCount = countSword
			for i in range(0, countSword + 1):
				(p, f) = (myCapacity, friendCapcity)
				p -= SwordWeight * i
				f -= (countSword - i) * SwordWeight
				if p >= 0 and f >= 0:
					TotalCount = max(TotalCount, countSword + p // WarAxeWeight + f // WarAxeWeight)
		print(min(TotalCount, countSword + countWarAxe))

def I():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

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

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

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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 solve(case):
	(p, f) = sep()
	(cnts, cntw) = sep()
	(s, w) = sep()
	if w < s:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	if f > p:
		(p, f) = (f, p)
	ans = 0
	for i in range(cnts + 1):
		if i * s > p:
			break
		pp = p
		ff = f
		cntss = cnts
		cntww = cntw
		temp = i
		cntss -= temp
		pp -= temp * s
		temp += min(cntww, pp // w)
		cntww -= min(cntww, pp // w)
		temp += min(cntss, ff // s)
		ff -= min(cntss, ff // s) * s
		temp += min(cntww, ff // w)
		ans = max(ans, temp)
	print(ans)
testcase(int(inp()))


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

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

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

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

def mips():
	return map(str, sys.stdin.readline().split())

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

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

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
t = ip()
while t:
	ans = 0
	t -= 1
	(p, f) = mip()
	(cs, cw) = mip()
	(s, w) = mip()
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for i in range(0, cs + 1):
		a_s = p // s
		count_sword = min(a_s, i)
		new_p = p - count_sword * s
		a_a = new_p // w
		count_axes = min(a_a, cw)
		cs_left = cs - count_sword
		cw_left = cw - count_axes
		a_s_f = f // s
		count_sword_f = min(a_s_f, cs_left)
		new_f = f - count_sword_f * s
		a_a_f = new_f // w
		count_axes_f = min(a_a_f, cw_left)
		total = count_axes + count_sword + count_sword_f + count_axes_f
		ans = max(ans, total)
	print(ans)


import sys
import math
import heapq
import collections
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def printspace(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer(' ')

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(p, f) = inputnums()
	(cnts, cntw) = inputnums()
	(s, w) = inputnums()
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(min(p // s, cnts) + 1):
		curcnts = cnts - i
		curcntw = cntw - min((p - i * s) // w, cntw)
		cur = i + min((p - i * s) // w, cntw)
		a = min(f // s, curcnts)
		cur += a + min((f - a * s) // w, curcntw)
		ans = max(cur, ans)
	print(ans)


for t in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		(ms, fs) = (i, cnts - i)
		ms = min(ms, p // s)
		fs = min(fs, f // s)
		rp = p - ms * s
		rf = f - fs * s
		(mw, fw) = (rp // w, rf // w)
		mw = min(mw, cntw)
		fw = min(fw, cntw - mw)
		tmp = ms + fs + mw + fw
		if tmp > ans:
			ans = tmp
	print(ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(p, f) = R()
	(a, b) = R()
	(x, y) = R()
	if x > y:
		(x, y) = (y, x)
		(a, b) = (b, a)
	s = min(a, p // x) * x
	a -= min(a, p // x)
	w = min(a, f // x) * x
	ans = s // x + w // x
	j = ans
	for i in range(s // x + 1):
		ans = max(ans, j + min(b, (p - s) // y + (f - w) // y))
		s -= x
		w += x
		if w > f:
			break
	print(ans)


import sys

def rl(proc=None):
	if proc is not None:
		return proc(sys.stdin.readline())
	else:
		return sys.stdin.readline().rstrip()

def srl(proc=None):
	if proc is not None:
		return list(map(proc, rl().split()))
	else:
		return rl().split()

def solve(p, f, cs, cw, s, w):
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	can = p // s + f // s
	if can <= cs:
		return can
	can1 = min(p // s, cs)
	can2 = cs - can1
	best = 0
	while can1 >= 0:
		left1 = p - can1 * s
		left2 = f - can2 * s
		if left2 < 0:
			break
		t = left1 // w + left2 // w
		if t >= cw:
			best = cw
			break
		best = max(best, t)
		can1 -= 1
		can2 += 1
	return best + cs

def main():
	T = rl(int)
	for t in range(1, T + 1):
		(p, f) = srl(int)
		(cs, cw) = srl(int)
		(s, w) = srl(int)
		print(solve(p, f, cs, cw, s, w))
main()


def main():
	for _ in range(int(input())):
		(p, f) = map(int, input().split())
		(cs, cw) = map(int, input().split())
		(s, w) = map(int, input().split())
		if s > w:
			(s, w) = (w, s)
			(cs, cw) = (cw, cs)
		ans = 0
		for s1 in range(cs + 1):
			if s1 * s > p:
				continue
			w1 = min(cw, (p - s1 * s) // w)
			s2 = min(cs - s1, f // s)
			w2 = min(cw - w1, (f - s2 * s) // w)
			ans = max(ans, s1 + s2 + w1 + w2)
		print(ans)
main()


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cnta, cntb) = map(int, input().split())
	(wa, wb) = map(int, input().split())
	if wa > wb:
		(wa, wb) = (wb, wa)
		(cnta, cntb) = (cntb, cnta)
	res = 0
	pa = 0
	while pa * wa <= p and pa <= cnta:
		pb = min((p - pa * wa) // wb, cntb)
		fa = min(cnta - pa, f // wa)
		fb = min((f - fa * wa) // wb, cntb - pb)
		res = max(res, pa + pb + fa + fb)
		pa += 1
	print(res)


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	(n, m) = map(int, stdin.readline().strip().split())
	(a, b) = map(int, stdin.readline().strip().split())
	(w1, w2) = map(int, stdin.readline().strip().split())
	if w2 < w1:
		x = b
		b = a
		a = x
		x = w2
		w2 = w1
		w1 = x
	ans = 0
	for i in range(0, a + 1):
		aux = 0
		x = n // w1
		if i > x:
			break
		y = n - i * w1
		aux += i + min(a - i, m // w1)
		z = m - min(a - i, m // w1) * w1
		aux += min(y // w2, b)
		w3 = b - min(y // w2, b)
		aux += min(z // w2, w3)
		ans = max(ans, aux)
	print(ans)


from math import ceil, sqrt

def main():
	t = int(input())
	for i in range(t):
		(p, f) = map(int, input().split())
		(count_a, count_b) = map(int, input().split())
		(a, b) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
			(count_a, count_b) = (count_b, count_a)
		ans = 0
		for i in range(count_a + 1):
			if i * a > p:
				break
			l = min(count_b, (p - i * a) // b)
			r = min(f // a, count_a - i)
			g = min(count_b - l, (f - r * a) // b)
			ans = max(ans, i + l + r + g)
		print(ans)
main()


import math
num_cases = int(input())
for _ in range(num_cases):
	(p, f) = list(map(int, input().strip().split()))
	(cnt_s, cnt_w) = list(map(int, input().strip().split()))
	(s, w) = list(map(int, input().strip().split()))
	ans = 0
	for i in range(0, cnt_s + 1):
		if s * i > p:
			break
		else:
			total = i
			ws = int((p - s * i) / w)
			ws = min(ws, cnt_w)
			total += ws
			ws_left = cnt_w - ws
			ss_left = cnt_s - i
			if s <= w:
				num1 = min(int(f / s), ss_left)
				num2 = min(int((f - num1 * s) / w), ws_left)
			else:
				num1 = min(int(f / w), ws_left)
				num2 = min(int((f - num1 * w) / s), ss_left)
			total += num2 + num1
			ans = max(ans, total)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = [int(x) for x in input().split()]
	(cs, cw) = [int(x) for x in input().split()]
	(s, w) = [int(x) for x in input().split()]
	maxWpCnt = -float('inf')
	for pcs in range(cs + 1):
		if pcs * s > p:
			break
		pcw = min(cw, (p - pcs * s) // w)
		remaining_cs = cs - pcs
		remaining_cw = cw - pcw
		if s < w:
			fcs = min(remaining_cs, f // s)
			fcw = min(remaining_cw, (f - fcs * s) // w)
		else:
			fcw = min(remaining_cw, f // w)
			fcs = min(remaining_cs, (f - fcw * w) // s)
		maxWpCnt = max(maxWpCnt, pcs + pcw + fcs + fcw)
	print(maxWpCnt)


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
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()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(my, frnd) = iia()
	(swrd, axe) = iia()
	(wtswrd, wtaxe) = iia()
	if wtswrd > wtaxe:
		(wtswrd, wtaxe) = (wtaxe, wtswrd)
		(swrd, axe) = (axe, swrd)
	res = 0
	for i in range(swrd + 1):
		if i * wtswrd > my:
			break
		sw1 = i
		ax1 = min((my - sw1 * wtswrd) // wtaxe, axe)
		sw2 = min(swrd - i, frnd // wtswrd)
		ax2 = min((frnd - sw2 * wtswrd) // wtaxe, axe - ax1)
		res = max(res, sw1 + sw2 + ax1 + ax2)
	print(res)


def read():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(p, f) = read()
	(cnts, cntw) = read()
	(s, w) = read()
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	res = 0
	for i in range(min(p // s, cnts) + 1):
		j = min((p - i * s) // w, cntw)
		k = min(f // s, cnts - i)
		l = min((f - k * s) // w, cntw - j)
		res = max(res, i + j + k + l)
	print(res)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	(a, b) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if s > w:
		(s, w) = (w, s)
		(a, b) = (b, a)
	if n < m:
		(n, m) = (m, n)
	ans = -10 ** 18
	for i in range(a + 1):
		cnt = 0
		(nx, mx, ax, bx) = [n, m, i, b]
		used = min(nx // s, ax)
		cnt += used
		nx -= used * s
		ax -= used - (a - i)
		used = min(mx // s, ax)
		cnt += used
		ax -= used
		mx -= used * s
		used = min(nx // w, bx)
		cnt += used
		nx -= used * w
		bx -= used
		used = min(mx // w, bx)
		cnt += used
		bx -= used
		mx -= used * w
		ans = max(ans, cnt)
	for i in range(b + 1):
		cnt = 0
		(nx, mx, ax, bx) = [n, m, a, i]
		used = min(nx // w, bx)
		cnt += used
		bx -= used - (b - i)
		nx -= used * w
		used = min(mx // w, bx)
		cnt += used
		bx -= used
		mx -= used * w
		used = min(nx // s, ax)
		cnt += used
		ax -= used
		nx -= used * s
		used = min(mx // s, ax)
		cnt += used
		ax -= used
		mx -= used * s
		ans = max(ans, cnt)
	print(ans)


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

def main():
	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):
		(p, f) = ria()
		(cnts, cntw) = ria()
		(s, w) = ria()
		if s > w:
			(s, w) = (w, s)
			(cnts, cntw) = (cntw, cnts)
		ans = 0
		for i in range(cnts + 1):
			ps = min(i, p // s)
			pw = min(cntw, (p - ps * s) // w)
			fs = min(cnts - ps, f // s)
			fw = min(cntw - pw, (f - fs * s) // w)
			ans = max(ps + fs + pw + fw, ans)
		print(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()


from sys import stdin, stdout

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

def ans(p, f, cs, cw, s, w):
	assert s <= w

	def ok(n):
		ns = 0
		nw = 0
		if n <= cs:
			ns = n
			nw = 0
		else:
			ns = cs
			nw = n - cs
		if not 0 <= ns <= cs:
			return False
		if not 0 <= nw <= cw:
			return False
		for ps in range(0, ns + 1):
			fs = ns - ps
			p_cap = p - ps * s
			f_cap = f - fs * s
			if p_cap < 0 or f_cap < 0:
				continue
			pw = p_cap // w
			fw = f_cap // w
			if pw + fw >= nw:
				return True
		return False
	low = 0
	high = 5 * 10 ** 5 + 10
	assert ok(low)
	assert not ok(high)
	while high - low > 5:
		mid = (low + high) // 2
		if ok(mid):
			low = mid
		else:
			high = mid
	for i in range(low, high + 1):
		if not ok(i):
			return i - 1

def ans2(p, f, cs, cw, s, w):
	if s > w:
		return ans(p, f, cw, cs, w, s)
	return ans(p, f, cs, cw, s, w)
T = int(input())
for t in range(T):
	(p, f) = input().split()
	(cs, cw) = input().split()
	(s, w) = input().split()
	print(ans2(int(p), int(f), int(cs), int(cw), int(s), int(w)))


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for _ in range(t):
		(cap1, cap2) = map(int, input().split())
		(swordcnt, axecnt) = map(int, input().split())
		(swordwt, axewt) = map(int, input().split())
		if swordwt > axewt:
			(swordwt, axewt) = (axewt, swordwt)
			(swordcnt, axecnt) = (axecnt, swordcnt)
		ans = 0
		for toKeep in range(swordcnt + 1):
			if toKeep * swordwt > cap1:
				break
			myS = toKeep
			hisS = min(cap2 // swordwt, swordcnt - myS)
			myLeft = cap1 - myS * swordwt
			hisLeft = cap2 - hisS * swordwt
			myA = min(myLeft // axewt, axecnt)
			hisA = min(hisLeft // axewt, axecnt - myA)
			ans = max(ans, myS + myA + hisS + hisA)
		print(ans)
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')
main()


for i in range(int(input())):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w <= s:
		if p // w + f // w <= cntw:
			print(p // w + f // w)
		else:
			answer = cntw
			k = 0
			while k * w <= p and k <= cntw:
				rem1 = p - k * w
				curr = k + min(cntw - k, f // w)
				rem2 = max(0, f - (cntw - k) * w)
				curr += min(rem1 // s + rem2 // s, cnts)
				answer = max(answer, curr)
				k += 1
			print(answer)
	elif p // s + f // s <= cnts:
		print(p // s + f // s)
	else:
		answer = cnts
		k = 0
		while k * s <= p and k <= cnts:
			rem1 = p - k * s
			curr = k + min(cnts - k, f // s)
			rem2 = max(0, f - (cnts - k) * s)
			curr += min(rem1 // w + rem2 // w, cntw)
			answer = max(answer, curr)
			k += 1
		print(answer)


def max_count(cns, s, cnw, w, weight):
	cs = min(cns, weight // s)
	weight -= s * cs
	cw = min(cnw, weight // w)
	return (cs, cw)
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cns, cnw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if p >= f:
		if s > w:
			(s, w) = (w, s)
			(cns, cnw) = (cnw, cns)
	else:
		(p, f) = (f, p)
		if s > w:
			(s, w) = (w, s)
			(cns, cnw) = (cnw, cns)
	ans = 0
	for i in range(cns + 1):
		(cs1, cw1) = max_count(i, s, cnw, w, p)
		(cs2, cw2) = max_count(cns - cs1, s, cnw - cw1, w, f)
		ans = max(ans, cs1 + cs2 + cw1 + cw2)
	print(ans)


import sys
input = sys.stdin.readline

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

def prog():
	for _ in range(int(input())):
		(p, f) = map(int, input().split())
		(cnts, cntw) = map(int, input().split())
		(s, w) = map(int, input().split())
		if s > w:
			(s, w) = (w, s)
			(cnts, cntw) = (cntw, cnts)
		mx = 0
		for i in range(cnts + 1):
			curr = 0
			lefts = cnts - i
			pleft = p
			fleft = f
			if i * s > p:
				curr += p // s
				pleft = p % s
			else:
				curr += i
				pleft -= i * s
			if lefts * s > f:
				curr += f // s
				fleft = f % s
			else:
				fleft -= lefts * s
				curr += lefts
			could_add = pleft // w + fleft // w
			curr += min(could_add, cntw)
			mx = max(mx, curr)
		print(mx)
prog()


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if w < s:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for i in range(cs + 1):
		count = min(i, p // s)
		np = p - count * s
		ns = cs - count
		count2 = min(cw, np // w)
		nw = cw - count2
		count3 = min(ns, f // s)
		nf = f - count3 * s
		count += count2 + count3 + min(nw, nf // w)
		ans = max(ans, count)
	print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(p, f) = sorted(I())
	(c1, c2) = I()
	(s, w) = I()
	if s > w:
		(s, w) = (w, s)
		(c1, c2) = (c2, c1)
	an = 0
	for i in range(c1 + 1):
		wt = i * s
		(a, b) = (p, f)
		x = 0
		cf = c2
		if wt <= b:
			b -= wt
			x = min(cf, b // w)
			cf -= x
			rm = c1 - i
			x += i
			px = min(rm, a // s)
			rm -= px
			a -= px * s
			x += px
			px = min(cf, a // w)
			x += px
		an = max(an, x)
	print(an)


def take_item(p, f, s_n, a_n, s_w, a_w):
	axe_p = min(p // a_w, a_n)
	a_n -= axe_p
	sword_f = min(f // s_w, s_n)
	f -= sword_f * s_w
	axe_f = min(f // a_w, a_n)
	return axe_p + axe_f + sword_f
for _ in range(int(input())):
	(p, f) = [int(x) for x in input().split()]
	(s_n, a_n) = [int(x) for x in input().split()]
	(s_w, a_w) = [int(x) for x in input().split()]
	res = 0
	if s_w > a_w:
		(s_w, a_w) = (a_w, s_w)
		(s_n, a_n) = (a_n, s_n)
	for i in range(min(s_n, p // s_w) + 1):
		tmp = i
		p1 = p - i * s_w
		s_n_1 = s_n - i
		tmp += take_item(p1, f, s_n_1, a_n, s_w, a_w)
		res = max(res, tmp)
	print(res)


import sys

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
from collections import defaultdict
for _ in range(ri()):
	(p, f) = ria()
	(a, b) = ria()
	(aw, bw) = ria()
	if aw > bw:
		(a, b) = (b, a)
		(aw, bw) = (bw, aw)
	ans = 0
	for i in range(a + 1):
		(a1, a2) = (a, aw)
		(b1, b2) = (b, bw)
		(x, y) = (p, f)
		cnt = 0
		if aw * i <= x:
			cnt = i
			a1 -= i
			x = x - a2 * i
		k = min(a1, y // a2)
		cnt += k
		y = y - aw * k
		a1 -= k
		k = min(b1, x // b2)
		cnt += k
		x = x - bw * k
		b1 -= k
		k = min(b1, y // b2)
		cnt += k
		y = y - bw * k
		b1 -= k
		ans = max(ans, cnt)
	print(ans)


import os
import sys, math
from io import BytesIO, IOBase

def func(cts, p, f, cnts, cntw, s, w):
	val = cts
	p -= cts * s
	cnts -= cts
	kitne = min(cntw, p // w)
	p -= kitne * w
	cntw -= kitne
	val += kitne
	if s < w:
		kitne = min(cnts, f // s)
		f -= kitne * s
		cnts -= kitne
		val += kitne
		kitne = min(cntw, f // w)
		f -= kitne * w
		cntw -= kitne
		val += kitne
	else:
		kitne = min(cntw, f // w)
		f -= kitne * w
		cntw -= kitne
		val += kitne
		kitne = min(cnts, f // s)
		f -= kitne * s
		cnts -= kitne
		val += kitne
	return val

def main():
	t = int(input())
	for case in range(t):
		(p, f) = list(map(int, input().split()))
		(cnts, cntw) = list(map(int, input().split()))
		(s, w) = list(map(int, input().split()))
		ans = 0
		for ct in range(min(cnts, p // s) + 1):
			ans = max(ans, func(ct, p, f, cnts, cntw, s, w))
		print(ans)
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')
main()


t = int(input())
for _ in range(t):
	(P, F) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(S, W) = map(int, input().split())
	p = max(P, F)
	f = min(P, F)
	s = min(S, W)
	w = max(S, W)
	if S > W:
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(min(cw, p // w) + 1):
		val = 0
		myaxes = i
		myswords = min((p - myaxes * w) // s, cs)
		hisswords = min(cs - myswords, f // s)
		hisaxes = min((f - hisswords * s) // w, cw - myaxes)
		val += myaxes + myswords + hisswords + hisaxes
		ans = max(ans, val)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	mx = 0
	for i in range(min(p // s + 1, cnts + 1)):
		cnts_c = cnts
		p_c = p
		cntw_c = cntw
		f_c = f
		ans = 0
		cnts_c -= i
		ans += i
		p_c -= i * s
		a = min(cntw_c, p_c // w)
		ans += a
		cntw_c -= a
		p_c -= w * a
		a = min(cnts_c, p_c // s)
		ans += a
		cnts_c -= a
		p_c -= s * a
		if s > w:
			a = min(cntw_c, f_c // w)
			ans += a
			cntw_c -= a
			f_c -= w * a
			a = min(cnts_c, f_c // s)
			ans += a
			cnts_c -= a
			f_c -= s * a
		else:
			a = min(cnts_c, f_c // s)
			ans += a
			cnts_c -= a
			f_c -= s * a
			a = min(cntw_c, f_c // w)
			ans += a
			cntw_c -= a
			f_c -= w * a
		mx = max(mx, ans)
	print(mx)


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')

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

def RLL():
	return list(RL())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // gcd(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from itertools import groupby

def main():
	for _ in range(N()):
		(p, f) = RL()
		(cs, cw) = RL()
		(ss, ww) = RL()
		res = 0
		for i in range(cs + 1):
			(s, w) = (ss, ww)
			now = 0
			ps = i * s
			if ps > p:
				break
			phav = p - ps
			numw = min(phav // w, cw)
			now += i + numw
			snum = cs - i
			wnum = cw - numw
			if s > w:
				(s, w) = (w, s)
				(snum, wnum) = (wnum, snum)
			fa = min(f // s, snum)
			fhav = f - fa * s
			now += fa
			now += min(fhav // w, wnum)
			res = max(res, now)
		print(res)
main()


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 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

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())):
	(p, f) = mp()
	(cnts, cntw) = mp()
	(s, w) = mp()
	ans = 0
	if s < w:
		mn = s
		mx = w
		mnc = cnts
		mxc = cntw
	else:
		mn = w
		mx = s
		mnc = cntw
		mxc = cnts
	for i in range(mnc + 1):
		(tp, tf) = (p, f)
		x = min(tp // mn, i)
		tp -= x * mn
		y = min(mxc, tp // mx)
		tp -= y * mx
		z = min(f // mn, mnc - x)
		tf -= z * mn
		z1 = min(tf // mx, mxc - y)
		tf -= z1 * mx
		ans = max(ans, x + y + z + z1)
	print(ans)


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

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

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

def inp():
	return int(input())

def st1():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	(fc, sc) = ma()
	(cs, ca) = ma()
	(cos, coa) = ma()
	(fc, sc) = (max(fc, sc), min(fc, sc))
	if cos > coa:
		(cos, coa) = (coa, cos)
		(cs, ca) = (ca, cs)
	capf = 0
	count = []
	for i in range(cs + 1):
		if cos * i > fc:
			continue
		re = fc - i * cos
		re1 = min(re // coa, ca)
		news = cs - i
		newa = ca - re1
		q1 = min(sc // cos, news)
		sc1 = sc - q1 * cos
		q2 = min(sc1 // coa, newa)
		count.append(i + re1 + q1 + q2)
	print(max(count))


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

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

def solve(p, f, cs, cw, s, w):
	(pc, fc) = (0, 0)
	sols = []
	ss = False
	if s < w:
		ss = True
	if ss:
		for i in range(cs + 1):
			pc = min(p // s, i)
			pr = p - pc * s
			fc = min(f // s, cs - i)
			fr = f - fc * s
			o = 0
			o += pr // w
			o += fr // w
			o = min(cw, o)
			sols.append(pc + fc + o)
		print(max(sols))
	else:
		for i in range(cw + 1):
			pc = min(p // w, i)
			pr = p - pc * w
			fc = min(f // w, cw - i)
			fr = f - fc * w
			o = 0
			o += pr // s
			o += fr // s
			o = min(cs, o)
			sols.append(pc + fc + o)
		print(max(sols))
tests = inInt()
for t in range(tests):
	p_and_f = inIList()
	p = p_and_f[0]
	f = p_and_f[1]
	cs_and_cw = inIList()
	cs = cs_and_cw[0]
	cw = cs_and_cw[1]
	s_and_w = inIList()
	s = s_and_w[0]
	w = s_and_w[1]
	solve(p, f, cs, cw, s, w)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	for i in range(min(cs + 1, p // s + 1)):
		t1 = cs - i
		t2 = (p - s * i) // w
		t3 = cw - t2
		t4 = min(f // s, t1)
		t5 = min((f - s * t4) // w, t3)
		ans = max(ans, i + t2 + t4 + t5)
	print(ans)


import io
import os

def solve(P, F, CS, CW, S, W):
	if S > W:
		(CS, CW) = (CW, CS)
		(S, W) = (W, S)
	best = 0
	for swordP in range(min(CS, P // S) + 1):
		warP = min(CW, (P - swordP * S) // W)
		swordF = min(CS - swordP, F // S)
		warF = min(CW - warP, (F - swordF * S) // W)
		assert swordP >= 0
		assert warP >= 0
		assert swordF >= 0
		assert warF >= 0
		assert P >= swordP * S + warP * W
		assert F >= swordF * S + warF * W
		assert swordP + swordF <= CS
		assert warP + warF <= CW
		best = max(best, swordP + warP + swordF + warF)
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(P, F) = [int(x) for x in input().split()]
	(CS, CW) = [int(x) for x in input().split()]
	(S, W) = [int(x) for x in input().split()]
	ans = solve(P, F, CS, CW, S, W)
	print(ans)


def byServant(f, s, sw, a, aw):
	ans = 0
	sICan = f // sw
	sICan = min(s, sICan)
	ans += sICan
	f -= sICan * sw
	aICan = f // aw
	aICan = min(aICan, a)
	ans += aICan
	return ans
t = int(input())
while t:
	t -= 1
	(p, f) = input().split()
	(p, f) = (int(p), int(f))
	(s, a) = input().split()
	(s, a) = (int(s), int(a))
	(sw, aw) = input().split()
	(sw, aw) = (int(sw), int(aw))
	items = [[sw, s], [aw, a]]
	items.sort()
	ans = 0
	sICan = p // items[0][0]
	sICan = min(items[0][1], sICan)
	for slifted in range(0, sICan + 1):
		temp_ans = slifted
		cap = p - slifted * items[0][0]
		aICan = cap // items[1][0]
		aICan = min(aICan, items[1][1])
		temp_ans += aICan
		temp_ans += byServant(f, items[0][1] - slifted, items[0][0], items[1][1] - aICan, items[1][0])
		ans = max(ans, temp_ans)
	print(ans)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

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

def main():
	(p, f) = vars()
	(p, f) = (max(p, f), min(p, f))
	(cs, cw) = vars()
	(s, w) = vars()
	if s > w:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	ans = 0
	x = 0
	while x <= cs:
		px = x
		py = cs - x
		(px, py) = (min(p // s, px), min(f // s, py))
		res = px + py
		np = p - px * s
		nf = f - py * s
		res += min(cw, np // w + nf // w)
		ans = max(ans, res)
		x += 1
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	main()


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(a, b, cx, cy, x, y):
	console('----- solving ------')
	(a, b) = sorted([a, b])
	if x > y:
		(x, y) = (y, x)
		(cx, cy) = (cy, cx)
	maxcnt = 0
	for i in range(cx + 1):
		ax = min(a // x, i)
		bx_max = cx - ax
		bx = min(b // x, bx_max)
		a_left = a - ax * x
		b_left = b - bx * x
		ay = min(a_left // y, cy)
		by_max = cy - ay
		by = min(b_left // y, by_max)
		maxcnt = max(maxcnt, ax + bx + ay + by)
	return maxcnt

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(p, f) = list(map(int, input().split()))
	(cs, cw) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	res = solve(p, f, cs, cw, s, w)
	print(res)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	cnt = list(map(int, input().split()))
	weights = list(map(int, input().split()))
	if weights[0] > weights[1]:
		low = 1
	else:
		low = 0
	ass = 0
	if f > p:
		(p, f) = (f, p)
	for i in range(min(cnt[low], p // weights[low]) + 1):
		lol = min(cnt[low - 1], (p - i * weights[low]) // weights[low - 1])
		lols = min(cnt[low] - i, f // weights[low])
		lolw = min(cnt[low - 1] - lol, (f - lols * weights[low]) // weights[low - 1])
		ass = max(ass, i + lol + lols + lolw)
	print(ass)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(sw, ax) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s > w:
		(s, w) = (w, s)
		(sw, ax) = (ax, sw)
	for i in range(sw + 1):
		(nf, ns) = (p, f)
		nf -= i * s
		if nf < 0:
			continue
		(nc, ncc) = (sw, ax)
		nc -= i
		res = min(ncc, nf // w) + i
		ncc -= min(ncc, nf // w)
		if nc:
			res += min(nc, ns // s)
			ns -= min(nc, ns // s) * s
		if ncc:
			res += min(ncc, ns // w)
		ans = max(res, ans)
	print(ans)


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if s >= w:
		pass
	else:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	for i in range(cntw + 1):
		(curp, curf) = (p, f)
		(curcnts, curcntw) = (cnts, cntw)
		temp = 0
		if i * w <= curp:
			temp += i
			curp -= i * w
		else:
			continue
		(q, r) = divmod(curp, s)
		if q >= curcnts:
			temp += curcnts
			curcnts = 0
		else:
			temp += q
			curcnts -= q
		(q, r) = divmod(curf, w)
		if q >= cntw - i:
			temp += cntw - i
			curf -= w * (cntw - i)
		else:
			temp += q
			curf -= w * q
		(q, r) = divmod(curf, s)
		if q >= curcnts:
			temp += curcnts
			curcnts = 0
		else:
			temp += q
			curcnts -= q
		ans = max(temp, ans)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())

	def solve(ps, pw, x, y, p2):
		if ps > pw:
			return solve(pw, ps, y, x, p2)
		if ps * x >= p2:
			return p2 // ps
		return x + min((p2 - x * ps) // pw, y)
	ans = 0
	for i in range(cs + 1):
		if i * s <= p:
			j = min((p - i * s) // w, cw)
			ans = max(ans, i + j + solve(s, w, cs - i, cw - j, f))
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cntS, cntW) = map(int, input().split())
	(s, w) = map(int, input().split())
	if w < s:
		(s, cntS, w, cntW) = (w, cntW, s, cntS)
	ans = 0
	for takeS_1 in range(0, cntS + 1):
		if takeS_1 * s > p:
			break
		takeW_1 = min(cntW, (p - takeS_1 * s) // w)
		remS = cntS - takeS_1
		remW = cntW - takeW_1
		takeS_2 = min(remS, f // s)
		takeW_2 = min(remW, (f - takeS_2 * s) // w)
		ans = max(ans, takeS_1 + takeW_1 + takeS_2 + takeW_2)
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	(p, f) = list(map(int, input().split()))
	(cntS, cntW) = list(map(int, input().split()))
	(s, w) = list(map(int, input().split()))
	if s < w:
		a = s
		cntA = cntS
		b = w
		cntB = cntW
	else:
		a = w
		cntA = cntW
		b = s
		cntB = cntS
	if cntA >= p // a + f // a:
		print(p // a + f // a)
	else:
		ans = 0
		for i in range(min(p // a + 1, cntA + 1)):
			cntP = min((p - i * a) // b, cntB)
			dB = cntB - cntP
			c = i + cntP
			cntF = min(f // a, cntA - i)
			d = f - cntF * a
			c += cntF + min(d // b, dB)
			ans = max(ans, c)
		print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	num = 0
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	for i in range(min(p // s, cnts) + 1):
		t1 = max(p - s * i, 0)
		t2 = max(cnts - i, 0)
		t3 = min(f // s, t2)
		t6 = max(f - t3 * s, 0)
		t4 = min(t1 // w, cntw)
		t9 = max(cntw - t4, 0)
		t1 = max(0, t1 - t4 * w)
		t5 = min(t9, t6 // w)
		num = max(num, i + t5 + t3 + t4)
	print(num)


ttt = int(input())
for _ in range(ttt):
	(p, f) = [int(x) for x in input().split()]
	(cnts, cntw) = [int(x) for x in input().split()]
	(s, w) = [int(x) for x in input().split()]
	if s < w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	qq = -1
	for swords in range(cnts + 1):
		count = swords
		left = p - s * swords
		lefts = cnts - swords
		leftw = cntw
		if left < 0:
			continue
		x = min(left // w, leftw)
		leftw -= x
		left -= w * x
		count += x
		left2 = f
		x = min(left2 // w, leftw)
		leftw -= x
		left2 -= w * x
		count += x
		x = min(left2 // s, lefts)
		lefts -= x
		left2 -= s * x
		count += x
		qq = max(qq, count)
	print(qq)


T = int(input())
for _ in range(0, T):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	for i in range(cs + 1):
		ks = cs
		kw = cw
		P = p
		F = f
		ct = 0
		if i * s <= P:
			P -= i * s
			ct += i
			ks -= i
			tt1 = min(P // w, kw)
			ct += tt1
			P -= tt1 * w
			kw -= tt1
			c11 = 0
			c22 = 0
			if s <= w:
				tt2 = min(F // s, ks)
				ct += tt2
				F -= tt2 * s
				ks -= tt2
				tt2 = min(F // w, kw)
				ct += tt2
				F -= tt2 * w
				kw -= tt2
			else:
				tt2 = min(F // w, kw)
				ct += tt2
				F -= tt2 * w
				kw -= tt2
				tt2 = min(F // s, ks)
				ct += tt2
				F -= tt2 * s
				ks -= tt2
			ans = max(ans, ct)
		else:
			break
	print(ans)


for test in range(int(input())):
	(p, f) = map(int, input().split())
	(cnt1, cnt2) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt1, cnt2) = (cnt2, cnt1)
	ans = 0
	f1 = f
	p1 = p
	for i in range(cnt1 + 1):
		f = f1
		p = p1
		if s * i <= p:
			now = i
			p -= s * i
			d = min(cnt1 - i, f // s)
			f -= d * s
			now += d
			x = min(cnt2, p // w)
			z = cnt2 - x
			now += x
			x = min(z, f // w)
			now += x
			ans = max(ans, now)
	print(ans)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	(p1, f1) = (p, f)
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	(ans1, ans2, ans3, ans4) = (0, 0, 0, 0)
	mas = []
	for i in range(min(cs, p // s) + 1):
		p = p1
		f = f1
		ans1 = i
		p -= s * ans1
		ans2 = max(0, min(cw, p // w))
		ans3 = max(0, min(cs - ans1, f // s))
		f -= ans3 * s
		ans4 = max(0, min(cw - ans2, f // w))
		mas.append(ans1 + ans2 + ans4 + ans3)
	print(max(mas))


import sys
input = sys.stdin.readline

def solution():
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	ans = 0
	for i in range(cnt_s + 1):
		j = cnt_s - i
		if i * s > p:
			break
		p_s = i
		f_s = min(j, f // s)
		p0 = p - p_s * s
		f0 = f - f_s * s
		ret = min(cnt_w, p0 // w + f0 // w) + p_s + f_s
		ans = max(ans, ret)
	print(ans)
T = int(input())
for _ in range(T):
	solution()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(cs + 1):
		ret = 0
		tp = p
		tf = f
		tcs = cs
		tcw = cw
		if s * i > p:
			break
		ret = i
		tp -= s * i
		tcs -= i
		p_axe = min(tcw, tp // w)
		ret += p_axe
		tcw -= p_axe
		f_swo = min(tcs, tf // s)
		ret += f_swo
		tf -= f_swo * s
		ret += min(tcw, tf // w)
		ans = max(ans, ret)
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(p, f) = map(int, input().split())
	(cnt_s, cnt_w) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if p < f:
		(p, f) = (f, p)
	if s > w:
		(s, w) = (w, s)
		(cnt_s, cnt_w) = (cnt_w, cnt_s)
	for i in range(cnt_s + 1):
		if i * s > p:
			break
		p2 = p - i * s
		ansp = 0
		ansp += i + min(cnt_w, p2 // w)
		rems = cnt_s - i
		remw = cnt_w - min(cnt_w, p2 // w)
		ansp += min(rems, f // s)
		f2 = f - s * min(rems, f // s)
		ansp += min(remw, f2 // w)
		ans = max(ans, ansp)
	print(ans)


for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if w < s:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	if f < p:
		(f, p) = (p, f)
	maxl = f // s + p // s
	maxl = min(maxl, cs)
	maximum = 0
	for i in range(maxl + 1):
		ans = 0
		if i * s > f or (maxl - i) * s > p:
			continue
		ans += maxl
		tf = f - i * s
		tp = p - (maxl - i) * s
		ans += min(tf // w + tp // w, cw)
		if ans > maximum:
			maximum = ans
	print(maximum)


import math
for _ in range(int(input())):
	(p, f) = map(int, input().split())
	(cntS, cntW) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cntS, cntW) = (cntW, cntS)
	ans = 0
	for sp in range(0, 1 + min(cntS, p // s)):
		wp = max(0, min(cntW, (p - sp * s) // w))
		sf = max(0, min(cntS - sp, f // s))
		wf = max(0, min(cntW - wp, (f - sf * s) // w))
		ans = max(ans, sp + wp + sf + wf)
	print(ans)


for _ in range(int(input())):
	(my_cap, f_cap) = map(int, input().split())
	(no_swords, no_axes) = map(int, input().split())
	(wt_swords, wt_axes) = map(int, input().split())
	if wt_swords > wt_axes:
		(wt_swords, wt_axes) = (wt_axes, wt_swords)
		(no_swords, no_axes) = (no_axes, no_swords)
	ans = 0
	for i in range(no_swords + 1):
		if i * wt_swords > my_cap:
			break
		s1 = i
		a1 = min(no_axes, (my_cap - s1 * wt_swords) // wt_axes)
		s2 = min(no_swords - s1, f_cap // wt_swords)
		a2 = min(no_axes - a1, (f_cap - s2 * wt_swords) // wt_axes)
		ans = max(ans, s1 + a1 + s2 + a2)
	print(ans)


T = int(input())
for t in range(T):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	ans = 0
	if w < s:
		(cs, cw) = (cw, cs)
		(s, w) = (w, s)
	ans = 0
	for i in range(cs + 1):
		(pp, ff, ccs, ccw) = (p, f, cs, cw)
		iuses = min(pp // s, i)
		pp -= iuses * s
		ccs -= iuses
		uuses = min(ff // s, ccs)
		ff -= uuses * s
		ccs -= uuses
		iusew = min(pp // w, ccw)
		ccw -= iusew
		uusew = min(ff // w, ccw)
		ff -= uusew * w
		ccw -= uusew
		ans = max(ans, uusew + uuses + iusew + iuses)
	print(ans)


cases = int(input())

def can_take(s, w, cs, cw, p):
	if s > w:
		return can_take(w, s, cw, cs, p)
	if s * cs >= p:
		return p // s
	return cs + min((p - s * cs) // w, cw)
while cases:
	(p, f) = [int(x) for x in input().split()]
	(cnts, cntw) = [int(x) for x in input().split()]
	(s, w) = [int(x) for x in input().split()]
	fans = 0
	for i in range(cnts + 1):
		if i * s <= p:
			j = min((p - i * s) // w, cntw)
			fans = max(fans, i + j + can_take(s, w, cnts - i, cntw - j, f))
	print(fans)
	cases -= 1


for t in range(int(input())):
	(p, f) = [int(k) for k in input().split()]
	(cs, cw) = [int(k) for k in input().split()]
	(s, w) = [int(k) for k in input().split()]
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	twea = 0
	for i in range(cs + 1):
		itp = p
		itf = f
		itcs = cs
		itcw = cw
		wea = 0
		if s * i <= itp:
			itp -= s * i
			itcs -= i
			wea += i
		wea += min(itp // w, itcw)
		itcw -= min(itp // w, itcw)
		wea += min(itcs, itf // s)
		itf -= s * min(itcs, itf // s)
		wea += min(itf // w, itcw)
		twea = max(twea, wea)
	print(twea)


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(P, F) = [int(_) for _ in input().split()]
	(cs, cw) = [int(_) for _ in input().split()]
	(ws, ww) = [int(_) for _ in input().split()]
	if ww < ws:
		(ws, ww) = (ww, ws)
		(cs, cw) = (cw, cs)
	capacity = P + F
	if cs * ws >= capacity:
		print(P // ws + F // ws)
		continue
	else:
		answer = 0
		for i in range(cs):
			wleft = i * ws
			if wleft > P:
				continue
			nb_right = min(cs - i, F // ws)
			answer = max(answer, i + nb_right + (P - wleft) // ww + (F - nb_right * ws) // ww)
		for i in range(cs):
			wleft = i * ws
			if wleft > F:
				continue
			nb_right = min(cs - i, P // ws)
			answer = max(answer, i + nb_right + (F - wleft) // ww + (P - nb_right * ws) // ww)
		print(min(answer, cw + cs))


tc = int(input())
for t in range(tc):
	(p, f) = map(int, input().split())
	(sw_cnt, ax_cnt) = map(int, input().split())
	(s_weight, ax_weight) = map(int, input().split())
	ans = 0
	k = min(sw_cnt + 1, p // s_weight + 1)
	for my_sw_cnt in range(k):
		ans_ = 0
		sw_cnt_ = sw_cnt
		ax_cnt_ = ax_cnt
		sw_cnt_ -= my_sw_cnt
		my_cap = p - my_sw_cnt * s_weight
		ans_ += my_sw_cnt
		my_ax_cnt = min(ax_cnt_, my_cap // ax_weight)
		ax_cnt_ -= my_ax_cnt
		my_cap = p - my_ax_cnt * ax_weight
		ans_ += my_ax_cnt
		if s_weight <= ax_weight:
			f_sw_cnt = min(sw_cnt_, f // s_weight)
			f_cap = f - f_sw_cnt * s_weight
			ans_ += f_sw_cnt
			f_ax_cnt = min(ax_cnt_, f_cap // ax_weight)
			ans_ += f_ax_cnt
		else:
			f_ax_cnt = min(ax_cnt_, f // ax_weight)
			f_cap = f - f_ax_cnt * ax_weight
			ans_ += f_ax_cnt
			f_sw_cnt = min(sw_cnt_, f_cap // s_weight)
			ans_ += f_sw_cnt
		ans = max(ans, ans_)
	print(ans)


t = int(input())
while t != 0:
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cnts, cntw) = (cntw, cnts)
	ans = 0
	for i in range(cnts + 1):
		if i * s > p:
			break
		first1 = i
		second1 = min(f // s, cnts - i)
		remain_first = p - i * s
		remain_second = f - second1 * s
		first2 = min(remain_first // w, cntw)
		second2 = min(remain_second // w, cntw - first2)
		ans = max(ans, first1 + second1 + first2 + second2)
	print(ans)
	t -= 1


import sys
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(p, f) = map(int, input().split())
	(sw_cc, ax_cc) = map(int, input().split())
	(sw_unit, ax_unit) = map(int, input().split())
	if ax_unit < sw_unit:
		(sw_cc, ax_cc) = (ax_cc, sw_cc)
		(sw_unit, ax_unit) = (ax_unit, sw_unit)
	mx = 0
	for cc in range(sw_cc + 1):
		if cc * sw_unit > p:
			break
		p_sw = cc
		p_ax = min(ax_cc, (p - p_sw * sw_unit) // ax_unit)
		(sw_rm, ax_rm) = (sw_cc - p_sw, ax_cc - p_ax)
		f_sw = min(sw_rm, f // sw_unit)
		f_ax = min(ax_rm, (f - f_sw * sw_unit) // ax_unit)
		mx = max(mx, p_sw + p_ax + f_sw + f_ax)
	print(mx)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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')

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = N()
for i in range(t):
	(p, f) = RL()
	(cs, cw) = RL()
	(s, w) = RL()
	if s > w:
		(s, w, cs, cw, p, f) = (w, s, cw, cs, f, p)
	ans = 0
	if p // s + f // s <= cs:
		ans = p // s + f // s
	else:
		ans = 0
		for i in range(max(0, cs - f // s), min(p // s, cs) + 1):
			tmp = cs + (p - i * s) // w + (f - (cs - i) * s) // w
			ans = max(ans, min(tmp, cs + cw))
	print(ans)


for _ in range(int(input())):
	(p, f) = [int(j) for j in input().split()]
	(counts, countw) = [int(j) for j in input().split()]
	(s, w) = [int(j) for j in input().split()]
	if s > w:
		g = w
		w = s
		s = g
		g = countw
		countw = counts
		counts = g
	ans = 0
	g = p // s
	g = min(g, counts)
	while g >= 0:
		temp = 0
		temp += g
		p1 = p - g * s
		s1 = counts - g
		b = min(p1 // w, countw)
		temp += b
		w1 = countw - b
		f1 = min(s1, f // s)
		temp += f1
		f2 = f - f1 * s
		cc = min(w1, f2 // w)
		temp += cc
		g -= 1
		ans = max(ans, temp)
	g = f // s
	g = min(g, counts)
	while g >= 0:
		temp = 0
		temp += g
		p1 = f - g * s
		s1 = counts - g
		b = min(p1 // w, countw)
		temp += b
		w1 = countw - b
		f1 = min(s1, p // s)
		temp += f1
		f2 = p - f1 * s
		cc = min(w1, f2 // w)
		temp += cc
		g -= 1
		ans = max(ans, temp)
	print(ans)


t = int(input())
ans = []
for i in range(t):
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	max1 = 0
	if s < w:
		for x in range(min(p // w, cntw) + 1):
			max1 = max(max1, x + min((p - w * x) // s, cnts) + min(f // s, cnts - min(cnts, (p - w * x) // s)) + min(cntw - x, (f - min(f // s, cnts - min(cnts, (p - w * x) // s)) * s) // w))
	else:
		for x in range(min(p // s, cnts) + 1):
			max1 = max(max1, x + min((p - s * x) // w, cntw) + min(f // w, cntw - min(cntw, (p - s * x) // w)) + min(cnts - x, (f - min(f // w, cntw - min(cntw, (p - s * x) // w)) * w) // s))
	ans.append(max1)
for i in ans:
	print(i)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(p, f) = map(int, input().split())
	(cs, cw) = map(int, input().split())
	(s, w) = map(int, input().split())
	if s > w:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ANS = 0
	for i in range(cs + 1):
		if i * s > p:
			break
		score = i
		rest_p = p - i * s
		rest_cs = cs - i
		pw = min(cw, rest_p // w)
		score += pw
		rest_cw = cw - pw
		fs = min(rest_cs, f // s)
		score += fs
		rest_f = f - fs * s
		score += min(rest_cw, rest_f // w)
		ANS = max(ANS, score)
	print(ANS)


import sys
(_ord, inp, num, neg, _Index) = (lambda x: x, [], 0, False, 0)
(i, s) = (0, sys.stdin.buffer.read())
try:
	while True:
		if s[i] >= b'0'[0]:
			num = 10 * num + _ord(s[i]) - 48
		elif s[i] == b'-'[0]:
			neg = True
		elif s[i] != b'\r'[0]:
			inp.append(-num if neg else num)
			(num, neg) = (0, False)
		i += 1
except IndexError:
	pass
if s and s[-1] >= b'0'[0]:
	inp.append(-num if neg else num)
_T_ = inp[_Index]
_Index += 1
for _t_ in range(_T_):
	(p, f) = inp[_Index:_Index + 2]
	_Index += 2
	(cs, cw) = inp[_Index:_Index + 2]
	_Index += 2
	(s, w) = inp[_Index:_Index + 2]
	_Index += 2
	if w < s:
		(s, w) = (w, s)
		(cs, cw) = (cw, cs)
	ans = 0
	for i in range(0, cs + 1):
		ptakes = min(p // s, i)
		ptakew = min(cw, (p - ptakes * s) // w)
		ftakes = min(cs - ptakes, f // s)
		ftakew = min(cw - ptakew, (f - ftakes * s) // w)
		ans = max(ans, ptakes + ptakew + ftakes + ftakew)
	print(ans)


import sys
input = sys.stdin.buffer.readline

def solution():
	(p, f) = map(int, input().split())
	(cnts, cntw) = map(int, input().split())
	(s, w) = map(int, input().split())
	num1 = 0
	num2 = 0
	ans = 0
	for i in range(cnts + 1):
		num1 = i
		if i * s > p:
			continue
		x = p - i * s
		num2 = min(cntw, x // w)
		x = num2 * w
		num1x = min(f // s, cnts - num1)
		num2x = num1x * s
		num1y = min(f // w, cntw - num2)
		num2y = num1y * w
		num1yy = min((f - num2y) // s, cnts - num1)
		num1xx = min((f - num2x) // w, cntw - num2)
		z = max(num1x + num1xx, num1y + num1yy)
		ans = max(ans, num1 + num2 + z)
	print(ans)
t = int(input())
for _ in range(t):
	solution()


for _ in range(int(input())):
	(ja, przyj) = map(int, input().split())
	(i_mie, i_sie) = map(int, input().split())
	(mie, sie) = map(int, input().split())
	if mie < sie:
		(mie, sie) = (sie, mie)
		(i_mie, i_sie) = (i_sie, i_mie)
	odp = 0
	for t_mie_j in range(i_mie + 1):
		if t_mie_j * mie > ja:
			break
		t_sie_j = min(i_sie, (ja - t_mie_j * mie) // sie)
		t_sie_p = min(i_sie - t_sie_j, przyj // sie)
		t_mie_p = min(i_mie - t_mie_j, (przyj - t_sie_p * sie) // mie)
		odp = max(odp, t_mie_j + t_mie_p + t_sie_j + t_sie_p)
	print(odp)