#include <bits/stdc++.h>
const int dx8[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy8[] = {0, 0, 1, -1, 1, -1, -1, 1};
const int dx4[] = {1, -1, 0, 0};
const int dy4[] = {0, 0, 1, -1};
using namespace std;
void task() {
  long long a, b;
  cin >> a >> b;
  string k, s = "0";
  cin >> k;
  s += k;
  int n = s.size();
  long long cost = 0;
  s += "0";
  vector<pair<int, int>> mines;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0' && s[i + 1] == '1') {
      int st = i + 1;
      i++;
      while (s[i] == '1') {
        i++;
      }
      mines.push_back(make_pair(st, i - 1));
      i--;
    }
  }
  n = mines.size();
  if (n == 0) {
    cout << "0\n";
    return;
  }
  if (n == 1) {
    cout << a << "\n";
    return;
  }
  mines.push_back(make_pair(INT_MAX, 0));
  bool blast = false;
  for (int i = 0; i < n; i++) {
    if (a < (b * (mines[i + 1].first - mines[i].second - 1))) {
      blast = true;
      cost += a;
    } else {
      blast = false;
      cost += (b * (mines[i + 1].first - mines[i].second - 1));
    }
  }
  if (!blast) {
    cost += a;
  }
  cout << cost << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int TT = 1;
  cin >> TT;
  while (TT--) {
    task();
  }
  return 0;
}
