#include #define ll long long using namespace std; #define N 100005 ll dp[N][2]; ll c1, c2, n; string s; ll fun(ll i, bool f) { if(i == n) { return 0; } ll& ans = dp[i][f]; if(ans != -1) { return ans; } if(f) { if(s[i] == 'B') { ans = min(fun(i + 1, 1) + c2, fun(i + 1, 0)); } else { ans = fun(i + 1, 1); } } else { if(s[i] == 'B') { ans = fun(i + 1, 0); } else { ans = fun(i + 1, 1) + c1; } } return ans; } void solve() { cin >> c1 >> c2 >> s; n = s.length(); for(int i = 0; i <= n; i++) { for(int j = 0; j < 2; j++) { dp[i][j] = -1; } } ll ans; if(s[0] == 'W') { ans = fun(1,1) + c1; } else { ans = fun(1,0); } cout << ans << endl; return; } int main() { int TESTS=1; cin >> TESTS; while(TESTS -- ) { solve(); } return 0; }