#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    s += "0";
    int n = s.size();
    vector<pair<int, int>> v;
    int i = 0;
    while (i < n) {
      if (s[i] == '1') {
        int j = i;
        while (j < n) {
          if (s[j] == '1')
            j++;
          else
            break;
        }
        v.push_back(make_pair(i, j - 1));
        i = j;
      } else
        i++;
    }
    int m = v.size();
    vector<int> x;
    for (int i = 1; i < v.size(); i++)
      x.push_back(v[i].first - v[i - 1].second - 1);
    sort(x.begin(), x.end());
    int k = 0;
    int a_min = m * a;
    int sum = 0;
    while (k < m && !x.empty()) {
      int cnt = (m - k) * a + sum * b;
      a_min = min(a_min, cnt);
      sum += x[k];
      k++;
    }
    cout << a_min << endl;
    t--;
  }
}
