#include <bits/stdc++.h>
using namespace std;
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  init();
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    if (s.find('1') == string::npos) {
      cout << 0 << "\n";
      continue;
    }
    deque<int> dq;
    for (auto e : s) dq.push_back(e - '0');
    while (int(dq.size()) && dq.front() == 0) dq.pop_front();
    while (int(dq.size()) && dq.back() == 0) dq.pop_back();
    long long cnt = 0, ans = a;
    for (int i = 1; i < int(dq.size()); i++) {
      if (dq[i] == 0)
        cnt++;
      else if (cnt) {
        ans += min(cnt * b, a);
        cnt = 0;
      }
    }
    cout << ans << "\n";
  }
}
