num=int(input())
for i in range(num):
x,y,z,w,n,m=map(int,input().split())
n1=list(map(int,input().split()))
if len(n1)==0:
print('%dg'%m,end='\n')
p=0
for c in n1:
m=m-n*p
if m<=0:
print('bye~Rabbit')
break
if c==1:
m=m+x
elif c==2:
m=m+y
elif c==3:
m=m-z
elif c==4:
m=m-w
p=p+1
elif c==0:
continue
if m>0:
print('%dg'%m,end='\n')