#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  while (s.size() > 0 && s[0] != '1') {
    s.erase(0, 1);
  }
  while (s.size() > 0 && s[s.size() - 1] != '1') {
    s.erase(s.size() - 1);
  }
  if (s.size() == 0) {
    cout << 0 << endl;
    ;
    return;
  }
  int c = 0, result = a, n = s.size();
  for (int i = 1; i < n; ++i) {
    if (s[i] == '1' && c > 0) {
      result += min(c * b, a);
      c = 0;
    } else if (s[i] == '0')
      ++c;
  }
  cout << result << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
