#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    vector<int> zeros;
    int L = 0, R = 0, n = s.size();
    while (R < n) {
      if (s[R] == '1') {
        int segment = R - L;
        if (segment && L) zeros.push_back(segment);
        while (R < n && s[R] == '1') R++;
        L = R;
      }
      R++;
    }
    int segmets_mines = 0;
    int L2 = 0, R2 = 0, n2 = s.size();
    while (R2 < n2) {
      if (s[R2] == '0') {
        int segment = R2 - L2;
        segmets_mines += (R2 - L2 != 0);
        while (R2 < n && s[R2] == '0') R2++;
        L2 = R2;
      }
      R2++;
    }
    segmets_mines += (s[s.size() - 1] == '1');
    int cnt_place = 0, segments_placement = 0;
    for (int i = 0; i < zeros.size(); i++) {
      if (zeros[i] * b + a < 2 * a) {
        cnt_place++;
        segments_placement += zeros[i];
      }
    }
    int minimum = (segmets_mines - cnt_place) * a;
    minimum += segments_placement * b;
    cout << minimum << endl;
  }
};
