#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long sign = 1, x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') sign = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + s - '0';
    s = getchar();
  }
  return x * sign;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x / 10) write(x / 10);
  putchar(x % 10 + '0');
}
int kase;
int n;
int k;
int a[(115000 + 5)];
multiset<int> s;
long long tree[(115000 + 5)];
void add(int pos, long long val) {
  for (int i = pos; i <= n; i += i & (-i)) {
    tree[i] += val;
  }
}
long long sum(int pos) {
  long long ans = 0;
  for (int i = pos; i; i -= i & (-i)) ans += tree[i];
  return ans;
}
struct node {
  int l, r;
  int len() const { return r - l + 1; }
  bool operator<(const node &rhs) const { return len() > rhs.len(); }
};
int m;
void solve() {
  cin >> m >> k;
  string str;
  cin >> str;
  long long ans = 0;
  int flag = 0;
  n = str.length();
  for (long long i = 0; i <= str.length() - 1; ++i) {
    a[i + 1] = str[i] - '0';
  }
  a[0] = a[n + 1] = 0;
  int it = 0;
  for (long long i = 1; i <= n + 1; ++i) {
    if (a[i]) {
      if (!flag) {
        flag = 1;
      }
    } else {
      if (flag) {
        ++it;
        flag = 0;
      }
    }
  }
  ans = it * m;
  int l, r;
  l = r = -1;
  for (long long i = 1; i <= n; ++i) {
    if (a[i]) {
      l = i;
      break;
    }
  }
  for (long long i = n; i >= 1; --i) {
    if (a[i]) {
      r = i;
      break;
    }
  }
  if (l == -1) {
    cout << 0 << endl;
    return;
  }
  flag = 0;
  priority_queue<node> q;
  for (long long i = l; i <= r; ++i) {
    if (!a[i]) {
      if (!flag) {
        flag = i;
      }
    } else {
      if (flag) {
        q.push({flag, int(i - 1)});
        flag = 0;
      }
    }
  }
  long long maxx = ans;
  while (q.size()) {
    node u = q.top();
    q.pop();
    maxx = min(maxx + (u.len() * k) - m, maxx);
  }
  cout << maxx << endl;
}
int main() {
  cin >> kase;
  while (kase--) {
    solve();
  }
  return 0;
}
