1 #include <iostream> 2 #include <string> 3 #define MAXN 27 4 using namespace std; 5 6 short map[MAXN]; 7 short cul[MAXN]; 8 9 int main() 10 { 11 //freopen("acm.acm","r",stdin); 12 int test; 13 int time; 14 int wait; 15 string s; 16 map[0] = 1; 17 map[1] = 1; 18 map[2] = 1; 19 20 map[3] = 2; 21 map[4] = 2; 22 map[5] = 2; 23 24 map[6] = 3; 25 map[7] = 3; 26 map[8] = 3; 27 28 map[9] = 4; 29 map[10] = 4; 30 map[11] = 4; 31 32 map[12] = 5; 33 map[13] = 5; 34 map[14] = 5; 35 36 map[15] = 6; 37 map[16] = 6; 38 map[17] = 6; 39 map[18] = 6; 40 41 map[19] = 7; 42 map[20] = 7; 43 map[21] = 7; 44 45 map[22] = 8; 46 map[23] = 8; 47 map[24] = 8; 48 map[25] = 8; 49 50 // cul[0] = 1; 51 cul[1] = 1; 52 cul[2] = 2; 53 cul[3] = 3; 54 55 cul[4] = 1; 56 cul[5] = 2; 57 cul[6] = 3; 58 59 cul[7] = 1; 60 cul[8] = 2; 61 cul[9] = 3; 62 63 cul[10] = 1; 64 cul[11] = 2; 65 cul[12] = 3; 66 67 cul[13] = 1; 68 cul[14] = 2; 69 cul[15] = 3; 70 71 cul[16] = 1; 72 cul[17] = 2; 73 cul[18] = 3; 74 cul[19] = 4; 75 76 cul[20] = 1; 77 cul[21] = 2; 78 cul[22] = 3; 79 80 cul[23] = 1; 81 cul[24] = 2; 82 cul[25] = 3; 83 cul[26] = 4; 84 cin>>test; 85 while(test --) 86 { 87 cin>>time>>wait; 88 getchar(); 89 getline(cin,s); 90 // cout<<s<<endl; 91 int sum = 0; 92 int i; 93 for(i = 0; i < s.length(); ++ i) 94 { 95 if(s[i] == ' ') 96 { 97 sum += time; 98 } 99 else if(i != 0 && map[s[i-1] - 'A'] != ' ' && map[s[i]-'A'] == map[s[i-1]-'A']) 100 { 101 sum += wait; 102 sum += cul[s[i]-'A'+1]*time; 103 } 104 else 105 { 106 sum += cul[s[i]-'A'+1]*time; 107 } 108 } 109 cout<<sum<<endl; 110 } 111 }