#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroint-loops")
long long int power(long long int b, long long int e, long long int m) {
  if (b == 0) return 0;
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long int power(long long int b, long long int e) {
  if (b == 0) return 0;
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
bool isPowerOfTwo(long long int x) { return (x && !(x & (x - 1))); }
void solve() {
  long long int a, b, p = 0, q = 0;
  string s;
  cin >> a >> b;
  cin >> s;
  vector<long long int> together, nottogether;
  bool flag = true;
  for (auto i : s) {
    if (i == '0') {
      if (p) together.push_back(p);
      p = 0;
      q++;
    } else {
      flag = false;
      p++;
      if (q && together.size() != 0) nottogether.push_back(q);
      q = 0;
    }
  }
  if (p) together.push_back(p);
  if (flag) {
    cout << 0;
    return;
  }
  if (together.size() == 1) {
    cout << a;
    return;
  }
  long long int ans = 0;
  long long int check = together.size();
  for (long long int i = 0; i < together.size() - 1; i++) {
    if (nottogether[i] * b + a < 2 * a) {
      check--;
      ans += nottogether[i] * b;
    }
  }
  cout << ans + check * a;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
    cout << "\n";
  }
  return 0;
}
