#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
long long pow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = ((res) * (x));
    res %= N;
    y = y >> 1;
    x = ((x) * (x));
  }
  return res;
}
long long pow(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  long long a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  vector<long long> tmp;
  for (long long i = 0; i < ((long long)(s).size()); i++) {
    if (s[i] == '1') tmp.push_back(i);
  }
  if (((long long)(tmp).size()) == 0) {
    cout << 0 << "\n";
    return;
  }
  long long ans = a;
  for (long long i = 1; i < ((long long)(tmp).size()); i++) {
    ans += min(a, (tmp[i] - tmp[i - 1] - 1) * b);
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
