#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int res = 0;
    int x = 9999;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        res = res + min(a, x * b);
        x = 0;
      } else {
        x++;
      }
    }
    cout << res << endl;
  }
}
