#include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template <typename T, typename... Args>
void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args)) cerr << ", ";
  DBG(args...);
}
const int N = 1e5;
int dp[N][2][2];
void solve() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  vector<int> v;
  int cnt = 0;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      v.push_back(i);
      cnt++;
    }
  }
  vector<int> gaps;
  for (int i = 1; i < v.size(); i++) {
    if (v[i] - v[i - 1] - 1) gaps.push_back(v[i] - v[i - 1] - 1);
  }
  sort(gaps.begin(), gaps.end());
  if (cnt == 0) {
    cout << 0 << "\n";
    return;
  }
  if (gaps.size() == 0) {
    cout << a << "\n";
    return;
  }
  int cost = a * gaps.size() + a;
  int size = gaps.size();
  int sum = 0;
  for (auto ele : gaps) {
    cost = min(cost, (ele + sum) * b + size * a);
    size--;
    sum += ele;
  }
  cout << cost << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
