#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  long long n = s.length();
  long long total = 0;
  long long l = n, r = -1;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') {
      l = min(l, i);
      r = max(r, i);
    }
  }
  if (l == n) {
    cout << "0\n";
    return;
  }
  bool zero = false;
  long long cost = 0;
  for (long long i = l; i <= r; i++) {
    if (s[i] == '0') {
      zero = true;
      long long j = i + 1;
      while (j <= r && s[j] == '0') j++;
      if (b * (j - i) <= a) {
        cost += b * (j - i);
      } else {
        cost += a;
      }
      i = j - 1;
    }
  }
  if (!zero)
    cost = a;
  else
    cost += a;
  cout << cost << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
