#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test;
  cin >> test;
  while (test--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int cnt = 0, idx = 0;
    vector<pair<int, int>> build;
    for (int i = 0; i < s.size(); i++) {
      int l = 0, r = 0;
      if (s[i] == '1') {
        l = i;
        int j = i;
        while (s[j] == '1' && j + 1 < s.size()) {
          j++;
          if (s[j] != '1') {
            --j;
            break;
          }
        }
        build.push_back({l, j});
        i = j;
      }
    }
    if (s.size() == 1) {
      if (s[0] == '0') {
        cout << 0 << "\n";
      } else
        cout << a << "\n";
      continue;
    }
    if (build.size() == 1) {
      cout << a << "\n";
      continue;
    }
    if (build.size() == 0) {
      cout << 0 << "\n";
      continue;
    }
    long long cost = build.size() * a;
    for (int i = 0; i < build.size() - 1; i++) {
      int diff = build[i + 1].first - build[i].second - 1;
      if (diff * b < a) {
        cost -= a;
        cost += diff * b;
      }
    }
    cout << cost << "\n";
  }
}
