#include <bits/stdc++.h>
using namespace std;
int t;
int a, b;
int sol;
string s;
void solve() {
  cin >> a >> b;
  cin >> s;
  int lung = s.length();
  s = " " + s;
  bool OK = 1;
  sol = 0;
  int ct = 0, poz = 0;
  s[0] = '0';
  for (int i = 1; i <= lung; i++) {
    if (s[i] == '1' && s[i - 1] == '0') {
      sol += a;
    }
    if (s[i] == '0' && s[i - 1] == '1') {
      ct = 0, poz = i;
      while (s[i] == '0' && i <= lung) ct++, i++;
      if (s[i] == '1') {
        i--;
        if (ct * b <= a) {
          s[i] = '1';
          sol += ct * b;
        }
      }
    }
  }
  cout << sol << '\n';
}
int main() {
  cin >> t;
  while (t--) solve();
}
