#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  int l1, r1, l2, r2;
  bool flag = false;
  int sum = 0, cnt = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == '0') {
      cnt++;
    } else if (s.at(i) == '1') {
      if (flag) {
        sum += min(cnt * b, a);
      }
      flag = true;
      cnt = 0;
    }
  }
  if (flag) {
    sum = sum + a;
  }
  cout << sum << "\n";
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
