#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x;
  cin >> x;
  while (x--) {
    long long a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    vector<pair<long long, long long>> dist;
    long long ans = 0;
    for (long long i = 0; i < s.length(); i++) {
      long long curr = i;
      if (s[i] == '1') {
        while (s[i] == '1') {
          i++;
        }
        dist.push_back(make_pair(curr, i));
      }
    }
    for (long long i = 1; i < dist.size(); i++) {
      if ((dist[i].first - dist[i - 1].second) * b < a) {
        ans += (dist[i].first - dist[i - 1].second) * b;
      } else {
        ans += a;
      }
    }
    if (dist.size() == 0) {
      cout << 0 << endl;
    } else {
      cout << ans + a << endl;
    }
  }
  return 0;
}
