#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  cin >> t;
  ;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    ;
    string s;
    cin >> s;
    long long n = s.length();
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '1') v.push_back(i);
    }
    if (v.size() == 0) {
      cout << 0 << "\n";
    } else if (v.size() == 1 || v.size() == n) {
      cout << a << "\n";
    } else {
      long long ans = a;
      for (long long i = 1; i < v.size(); i++) {
        if (v[i] - v[i - 1] - 1 == 0)
          continue;
        else {
          long long x = (v[i] - v[i - 1] - 1);
          ans += min(a, b * x);
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
