#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  long long ans = 0, prev;
  bool flag = true;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == '1') {
      while (i < s.length() && s[i] == '1') i++;
      long long cnt = 0;
      while (i < s.length() && s[i] == '0') {
        cnt++;
        i++;
      }
      i--;
      if (flag) {
        ans += a;
        prev = cnt;
        flag = false;
      } else {
        ans += min(a, prev * b);
        prev = cnt;
      }
    }
  }
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long TC;
  cin >> TC;
  while (TC--) {
    solve();
  }
  return 0;
}
