t = int(input())
abc = [[int(i) for i in input().split()] for j in range(t)]

for i in range(t):
    ans = 10**20
    a,b,c = abc[i][:3]
    x,y,z = abc[i][3:]#x:c,y:a,z,b

    #大きい順a,c,b
    aa,bb,cc = a,b,c
    tmp = 0
    t1,t2 = 0,0
    if cc <= bb:
        t1 = abs((bb+1)-cc)#a,b
        tmp += t1*x
        cc = bb+1
    if aa <= cc:
        t2 = abs((cc+1)-aa)#b,c
        tmp += t2*y
        aa = bb+1
    if t1 < a and t1+t2 < b and t2 < c:
        ans = min(tmp,ans)

    #大きい順b,c,a
    aa,bb,cc = a,b,c
    tmp = 0
    t1,t2 = 0,0
    if cc <= aa:
        t1 = abs((aa+1)-cc)#a,b
        tmp += t1*x
        cc = aa+1
    if bb <= cc:
        t2 = abs((cc+1)-bb)#a,c
        tmp += t2*z
        bb = cc+1
    if t1+t2 < a and t1 < b and t2 < c:
        ans = min(tmp,ans)

    #大きい順b,a,c
    aa,bb,cc = a,b,c
    tmp = 0
    t1,t2 = 0,0
    if aa <= cc:
        t1 = abs((cc+1)-aa)#c,b
        tmp += t1*y
        aa = cc+1
    if bb <= aa:
        t2 = abs((aa+1)-bb)#a,c
        tmp += t2*z
        bb = aa+1
    if t2 < a and t1 < b and t1+t2 < c:
        ans = min(tmp,ans)


    #大きい順c,a,b
    aa,bb,cc = a,b,c
    tmp = 0
    t1,t2 = 0,0
    if aa <= bb:
        t1 = abs((bb+1)-aa)#b,c
        tmp += t1*y
        aa = bb+1
    if cc <= aa:
        t2 = abs((aa+1)-cc)#a,b
        tmp += t2*x
        cc = aa+1
    if t2 < a and t1+t2 < b and t1 < c:
        ans = min(tmp,ans)

    if ans == 10**20:
        print(-1)
    else:
        print(ans)