#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  int n = s.size();
  int c = 0, d = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      c++;
    else
      break;
  }
  for (int j = n - 1; j >= 0; j--) {
    if (s[j] == '0')
      d++;
    else
      break;
  }
  vector<int> v;
  int m = 0;
  for (int i = c; i <= n - 1 - d; i++) {
    if (s[i] == '0') {
      m++;
    } else {
      if (m != 0) v.push_back(m);
      m = 0;
    }
  }
  int f = 0;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1' && f == 0) {
      ans += a;
      f = 1;
    } else if (s[i] == '0') {
      f = 0;
    }
  }
  int k = v.size();
  sort(v.begin(), v.end());
  for (int i = 0; i < k; i++) {
    if (b * v[i] < a) {
      ans -= a;
      ans += b * v[i];
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
