#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void solve(vector<int> v, int s, int i, int sum, int a, int b) {
  if (s * a < (v[0] * b + a * (s - 1))) {
    ans = s * a;
    return;
  }
  if (i >= v.size()) return;
  if (i < v.size()) {
    if (i == 0) ans = s * a;
    if (ans > (b * sum + a * (s - i - 1))) {
      ans = (b * sum + a * (s - i - 1));
      solve(v, s, i + 1, sum + v[i + 1], a, b);
    }
  } else
    return;
}
int main() {
  int a, b, t;
  string s;
  vector<int> gv;
  int seg = 0, g = 0;
  cin >> t;
  while (t--) {
    ans = 0;
    seg = 0;
    g = 0;
    cin >> a >> b;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1' && (s[i + 1] == '0' || i == s.length() - 1)) {
        seg++;
        if (g != 0) {
          gv.push_back(g);
          g = 0;
        }
      }
      if (seg != 0 && s[i] == '0') g++;
    }
    sort(gv.begin(), gv.end());
    if (!gv.empty())
      solve(gv, seg, 0, gv[0], a, b);
    else if (seg != 0)
      ans = a;
    cout << ans << "\n";
    gv.erase(gv.begin(), gv.end());
  }
  return 0;
}
