#include <bits/stdc++.h>
using namespace std;
const char newl = '\n';
void DEBUGLOCAL() { cerr << ")" << newl; }
template <class A, class... B>
void DEBUGLOCAL(A argc, B... argv) {
  cerr << argc;
  if (sizeof...(argv)) cerr << ", ";
  DEBUGLOCAL(argv...);
}
int ts;
int a, b;
string s;
void solve() {
  cin >> a >> b >> s;
  s += '0';
  int ones = 0, zeros = 0, ok = 0, ans = 0;
  for (int i = 0; i < (int)(s).size(); ++i) {
    zeros += s[i] == '0';
    ones += s[i] == '1';
    if (s[i] == '1' && s[i + 1] == '0') {
      int tmp = a;
      if (ok) tmp = min(tmp, b * zeros);
      ans += tmp;
      zeros = 0, ones = 0, ok = 1;
    }
  }
  cout << ans << newl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> ts;
  while (ts--) solve();
}
