#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long Mod = 1e9 + 7;
const long long inf = 1e18;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    long long cnt = 0;
    bool ok = false;
    long long n = (long long)s.size();
    long long one = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '1') {
        cnt++;
      } else if (s[i] == '0' && cnt) {
        one++;
        cnt = 0;
      }
    }
    if (cnt) one++;
    debug() << "\033[0;33mLine(" << 114 << ")\033[0m"
            << "\033[1;36m->"
            << "\033[0m"
            << "\033[94m ["
            << "one"
               ": "
            << (one) << "]\033[0m";
    cnt = 0;
    vector<long long> len;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '1') ok = true;
      if (ok && s[i] == '0') {
        cnt++;
      } else {
        len.push_back(cnt);
        cnt = 0;
      }
    }
    debug() << "\033[0;33mLine(" << 126 << ")\033[0m"
            << "\033[1;36m->"
            << "\033[0m"
            << "\033[94m ["
            << "len"
               ": "
            << (len) << "]\033[0m";
    long long A = 0, B = 0;
    A = one;
    for (long long i : len) {
      if (i == 0) continue;
      long long x = b * i;
      if (x < a) {
        A--;
        B += i;
      }
    }
    long long ans = (a * A) + (b * B);
    cout << ans << '\n';
  }
}
