#include <iostream>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
int cnt_f,cnt=0;
stringstream stream;
string s,a;
cin>>cnt_f;
cin.ignore();
int num[cnt_f];
while(cnt<cnt_f)
{
s.clear();
getline(cin,s);
stream.clear();
stream<<s;
int x,y,z,w,n,m =0;
stream>>x>>y>>z>>w>>n>>m;
num[cnt]=m;
a.clear();
getline(cin,a);
stream.clear();
stream<<a;
int temp,p=0;
bool flag = 0;
while(stream>>temp)
{
if(flag==1)
{
num[cnt] -= n*p;
}
if(num[cnt]>0)
{
switch(temp)
{
case 1:
num[cnt] += x;
break;
case 2:
num[cnt] += y;
break;
case 3:
num[cnt] -= z;
break;
case 4:
num[cnt] -= w;
p++;
flag=1;
break;
default:
break;
}
if(num[cnt]<=0)
{
num[cnt]= -1;
break;
}
}
else
{
num[cnt]= -1;
break;
}
}
cnt++;
}
for(int i=0;i<cnt_f;i++)
{
if(num[i]>0)
{
cout<<num[i]<<"g"<<endl;
}
else
{
cout<<"bye~Rabbit"<<endl;
}
}
return 0;
}