import sys input = sys.stdin.readline T = int(input()) for _ in range(T): A, B, C = map(int, input().split()) X, Y, Z, W = map(int, input().split()) ans = 0 for i in range(min(A, B, C) + 1): now = W * i tA, tB, tC = A - i, B - i, C - i now += X * min(tA, tB) tA, tB = A - min(A, B), B - min(A, B) if tA: now += Z * min(tA, tC) else: now += Y * min(tB, tC) ans = max(now, ans) now = W * i tA, tB, tC = A - i, B - i, C - i now += Y * min(tB, tC) tB, tC = B - min(B, C), C - min(B, C) if tB: now += X * min(tA, tB) else: now += Z * min(tA, tC) ans = max(now, ans) now = W * i tA, tB, tC = A - i, B - i, C - i now += Z * min(tA, tC) tA, tC = A - min(A, C), C - min(A, C) if tA: now += X * min(tA, tB) else: now += Y * min(tB, tC) ans = max(now, ans) print(ans)