#include <bits/stdc++.h>
using namespace std;
void pairsort(long long a[], long long b[], long long n) {
  pair<long long, long long> pairt[n];
  for (long long i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (long long i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
long long gcd(long long a, long long b) {
  if (b > a)
    return gcd(b, a);
  else if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long manual_log(long long num, long long base) {
  long long result = 0;
  while (num > 1) {
    result++;
    num = num / base;
  }
  return result;
}
void solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
void solve() {
  long long a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  long long n = s.size();
  priority_queue<long long, vector<long long>, greater<long long> > pq;
  vector<long long> v;
  long long count = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') v.push_back(i);
  }
  v.push_back(n + 1);
  if (v.size() == 1)
    cout << 0;
  else {
    for (long long i = 1; i <= v.size() - 1; i++) {
      if (i < v.size() - 1) {
        if ((v[i] - v[i - 1]) > 1) {
          count++;
          pq.push(v[i] - v[i - 1] - 1);
        }
      } else {
        if ((v[i] - v[i - 1]) > 1) count++;
      }
    }
    if (count == 1)
      cout << a;
    else {
      long long ans = count * a;
      while (pq.size()) {
        long long x = pq.top();
        long long temp = (ans - a) + x * b;
        if (temp >= ans)
          break;
        else
          ans = temp;
        pq.pop();
      }
      cout << ans;
    }
  }
}
