#include <bits/stdc++.h>
using namespace std;
int t;
int a, b;
string s;
vector<pair<int, int>> v;
void setval(string& x, int l, int r) {
  for (int i = l; i <= r; i++) x[i] = '1';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> a >> b >> s;
    int l = 0, r = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        if (i == 0 || s[i - 1] == '0') v.push_back({i, 0});
        if (i == s.size() - 1 || s[i + 1] == '0') v.back().second = i;
      }
    }
    long long ans = 0;
    for (int i = 1; i < v.size(); i++) {
      if (b * (v[i].first - v[i - 1].second - 1) <= a)
        setval(s, v[i - 1].second + 1, v[i].first - 1),
            ans += 1LL * b * (1LL * v[i].first - v[i - 1].second - 1);
    }
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        ans += a;
        while (i < s.size() && s[i] == '1') {
          i++;
        }
      }
    }
    cout << ans << "\n";
    v.clear();
  }
  return 0;
}
