#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = (ll)1e18;
constexpr ll MOD = 998244353;
constexpr double EPS = 1e-9;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
constexpr ll dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr ll dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
void p() { std::cout << '\n'; }
template <typename Head, typename... Tail>
void p(Head head, Tail... tail) {
  std::cout << head << (sizeof...(tail) ? " " : "");
  p(tail...);
}
template <typename T>
inline void pv(std::vector<T>& v) {
  for (ll i = 0, N = v.size(); i < N; i++)
    std::cout << v[i] << " \n"[i == N - 1];
}
template <typename T>
inline bool chmax(T& a, T b) {
  return a < b && (a = b, true);
}
template <typename T>
inline bool chmin(T& a, T b) {
  return a > b && (a = b, true);
}
template <typename T>
inline void uniq(std::vector<T>& v) {
  v.erase(std::unique(v.begin(), v.end()), v.end());
}
vector<pair<char, ll>> runLengthEncoding(string s) {
  vector<pair<char, ll>> ans;
  char ch = s[0];
  ll count = 0;
  for (ll i = 0, size = s.size(); i < size; i++) {
    if (ch == s[i]) {
      count++;
    } else {
      ans.push_back({ch, count});
      ch = s[i];
      count = 1;
    }
  }
  ans.push_back({ch, count});
  return ans;
}
void solve() {
  ll A, B;
  cin >> A >> B;
  string S;
  cin >> S;
  auto run = runLengthEncoding(S);
  ll ans = 0;
  for (ll i = 0, i_length = (run.size()); i < i_length; ++i) {
    if (run[i].first == '1') ans += A;
  }
  for (ll i = 0, i_length = (run.size()); i < i_length; ++i) {
    if (run[i].first == '0' && (i == 0 || i == (ll)run.size() - 1)) continue;
    auto [ch, count] = run[i];
    if (ch == '0') {
      ll t = B * count;
      if (A > t) {
        ans -= A;
        ans += t;
      }
    }
  }
  p(ans);
}
signed main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll Q;
  cin >> Q;
  while (Q--) solve();
  return 0;
}
