#include <bits/stdc++.h>
using namespace std;
void r_p05() {
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
void run_test_cases() {
  long long a, b;
  cin >> a >> b;
  string str;
  cin >> str;
  long long prev = -1;
  long long ans = 0;
  long long n = str.size();
  for (long long i = 0; i < n; i++) {
    if (str[i] == '0') {
      continue;
    }
    if (prev == -1) {
      prev = i;
      ans += a;
    } else {
      ans += min(a, (i - prev - 1) * b);
      prev = i;
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  r_p05();
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    run_test_cases();
  }
  return 0;
}
