#include <bits/stdc++.h>
using namespace std;
int solve(const string& s, int a, int b) {
  int n = s.size();
  vector<pair<int, int>> runs;
  int start = -1;
  bool in_run = false;
  for (int i = 0; i <= n; ++i) {
    if ((i == n) || (s[i] == '0')) {
      if (in_run) {
        runs.emplace_back(start, i);
        in_run = false;
      }
    } else if (!in_run) {
      start = i;
      in_run = true;
    }
  }
  int m = runs.size();
  if (m == 0) {
    return 0;
  }
  int cost = a;
  for (int i = 1; i < m; ++i) {
    int gap = runs[i].first - runs[i - 1].second;
    cost = min(cost + a, cost + b * gap);
  }
  return cost;
}
void test_case() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  int solution = solve(s, a, b);
  cout << solution << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    test_case();
  }
}
