#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    string s;
    cin >> a >> b >> s;
    long long sum = 0;
    vector<pair<long long, long long>> ch;
    int l = s.length();
    for (long long i = 0; i < l; i++) {
      if (s[i] == '1') {
        ch.push_back({1, i});
      }
    }
    l = ch.size();
    if (l == 0) {
      cout << "0" << endl;
      continue;
    }
    sum = a;
    for (long long i = 0; i < l - 1; i++) {
      long long cost = (ch[i + 1].second - ch[i].second - 1) * b;
      if (cost < a) {
        sum += cost;
      } else {
        sum += a;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
