//zerojudge_a271_1222.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int t;
scanf("%d", &t);
while(t--)
{
long long int x,y,z,w,n,m;
scanf("%lld %lld %lld %lld %lld %lld ", &x, &y, &z, &w, &n, &m);
long long int poison = 0, weight = m, flag = 1, len;
char command[1001];
gets(command);
len = strlen(command);
for(int i = 0; i < len; i++)
{
if(command[i] == ' ')
continue;
weight -= poison;
if(weight <= 0)
{
printf("bye~Rabbit\n");
flag = 0;
break;
}
switch(command[i])
{
case '0':
break;
case '1':
weight += x;
break;
case '2':
weight += y;
break;
case '3':
weight -= z;
break;
case '4':
weight -= w;
poison += n;
break;
}
if(weight <= 0)
{
printf("bye~Rabbit\n");
flag = 0;
break;
}
}
if(flag)
printf("%lldg\n", weight);
}
return 0;
}