time = int(input())
for i in range(time):
num = list(map(int,input().split()))
carrot = list(map(int,input().split()))
x ,y, z = num[0], num[1], num[2]
w ,n,m = num[3], num[4], num[5]
toxic = 0
if carrot ==0:
print(m)
else:
for i in carrot:
m -= toxic*n
if i ==1:
m+= x
if i ==2:
m+=y
if i==3:
m-=z
if i ==4 :
m-=w
toxic+=1
if m <=0:
print("bye~Rabbit")
break
else:
print(str(m)+"g")