#include <bits/stdc++.h>
using namespace std;
int n;
int a, b;
vector<int> arr;
vector<vector<int> > dp;
void solve1(string x, int a, int b) {
  int n = x.length();
  int l = n + 1;
  int r = -1;
  for (int i = 0; i < n; i++) {
    if (x[i] == '1') {
      l = min(l, i);
      r = max(r, i);
    }
  }
  if (l > r) {
    cout << 0 << endl;
    return;
  }
  int ans = a;
  int curr = 0;
  for (int i = l; i <= r; i++) {
    if (x[i] == '0')
      curr++;
    else {
      ans += min(a, curr * b);
      curr = 0;
    }
  }
  cout << ans << endl;
}
int solve(int idx, int prev, int sz) {
  if (idx == sz) {
    return prev == 1;
  } else if (idx > sz) {
    return 0;
  }
  if (dp[idx][prev] != -1) return dp[idx][prev];
  int ans = INT_MAX;
  ans = min(ans, solve(idx + 1, 0, sz) + 2 * a);
  ans = min(ans, solve(idx + 2, 1, sz) + ((arr[idx] * b) + a) -
                     (idx > 0 ? a * (1 - prev) : 0));
  return dp[idx][prev] = ans;
}
void testcase(int tc) {
  cin >> a >> b;
  string x;
  cin >> x;
  solve1(x, a, b);
  return;
  n = x.length();
  arr.clear();
  int l = n + 1, r = -1;
  for (int i = 0; i < n; i++) {
    if (x[i] == '1') {
      l = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (x[i] == '1') {
      r = i;
      break;
    }
  }
  if (l > r || l == n + 1 || r == -1) {
    cout << 0 << endl;
    return;
  }
  int curr = 0;
  for (int i = l; i <= r; i++) {
    if (x[i] == '0')
      curr++;
    else {
      if (curr > 0) {
        arr.push_back(curr);
      }
      curr = 0;
    }
  }
  int sz = arr.size();
  if (sz == 0) {
    cout << a << endl;
    return;
  } else {
    dp.clear();
    dp.resize(sz + 9, vector<int>(4, -1));
    cout << solve(0, 0, sz) << endl;
    return;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    testcase(i);
  }
  return 0;
}
