#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
long long int a, b;
string s;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void solve() {
  cin >> a >> b >> s;
  long long int gaps = 0, ones = 0;
  long long int i = 0;
  long long int n = s.size();
  vector<pair<long long int, long long int> > seg;
  char ch = s[0];
  long long int len = 1;
  for (long long int i = 1; i < n; i++) {
    if (s[i] == ch)
      len++;
    else {
      seg.push_back({ch - '0', len});
      len = 1;
      ch = s[i];
    }
  }
  seg.push_back({ch - '0', len});
  long long int ans = 0;
  for (; i < seg.size(); i++) {
    if (seg[i].first == 1) break;
  }
  long long int j = seg.size() - 1;
  for (; j > i; j--) {
    if (seg[j].first == 1) break;
  }
  if (seg.size() >= 2 or seg[0].first == 1) ans += a;
  for (long long int k = i + 2; k <= j; k += 2) {
    if (k - 1 >= 0 and seg[k - 1].second * b <= a) {
      ans += seg[k - 1].second * b;
    } else {
      ans += a;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
