#include <bits/stdc++.h>
using namespace std;
void debug() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug(Head a, Tail... b) {
  cerr << a << " ";
  debug(b...);
}
template <class T>
void umin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void umax(T &a, T b) {
  a = max(a, b);
}
const int mod = 1e9 + 7, N = 1e6 + 5;
void solve() {
  int a, b;
  cin >> a >> b;
  string second;
  cin >> second;
  bool ok = 0;
  for (int i = 0; i < (int)((second).size()); ++i) {
    if (second[i] == '1') {
      ok = 1;
    }
  }
  if (!ok) {
    cout << "0\n";
    return;
  }
  vector<int> v;
  int ans = 0;
  for (int i = 0; i < (int)((second).size()); ++i) {
    if (second[i] == '0') continue;
    if (i == 0)
      v.push_back(i);
    else {
      if (second[i - 1] == '1') {
        v.pop_back();
        v.push_back(i);
      } else {
        if ((int)((v).size())) {
          int r = i - v.back() - 1;
          if (r * b + a < a + a) {
            ans += r * b;
          } else
            ans += a;
        }
        v.push_back(i);
      }
    }
  }
  ans += a;
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) solve();
}
