#include <bits/stdc++.h>
constexpr int MOD = 1e9 + 7;
const int N = 50000;
using namespace std;
long long int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(int a, int b) { return a / gcd(a, b) * b; }
void solve() {
  long long int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  long long int ans = 0, d = 1e9;
  for (auto x : s) {
    if (x == '1') {
      ans += min(a, b * d);
      d = 0;
    } else
      d++;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
