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

Starter code:

Solutions:
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)



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

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

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)

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


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)



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)


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


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

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)

gans = []
for _ in range(int(input())):
    p, f = list(map(int, input().split()))
    n, m = list(map(int, input().split()))
    s, w = list(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)))


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

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


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
        #if i == 3:
            #print(p - i*s, f - (cs-i)*s, "!")
        best = max(best, min(cw, (p - i*s)//w + (f - (cs-i)*s)//w) + cs)
    print(best)