#include <iostream>
#include <sstream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int i, times;
int x, y, z, w, n, m;
string line, Line;
cin >> times;
for(i = 0; i < times;i++){
int carrot = 0, poisondamage = 0;
cin >> x >> y >> z >> w >> n >> m;
cin.ignore();
getline(cin,Line);
stringstream SS(Line);
if(Line == ""){
cout << m << "g" << endl;
continue;
}
while(SS >> carrot){
SS.clear();
m -= (poisondamage * n);
if(m <= 0){
cout << "bye~Rabbit\n";
break;
}
if(carrot == 0){
continue;
}
else if(carrot == 1){
m += x;
}
else if(carrot == 2){
m += y;
}
else if(carrot == 3){
m -= z;
}
else if(carrot == 4){
m -= w;
poisondamage += 1;
}
if(m <= 0){
cout << "bye~Rabbit\n";
break;
}
}
if(m > 0){
cout << m << "g\n";
}
}
}
cin.ignore()的位置要看清楚,break跟continue的使用時機