#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int n = s.size();
    int first = -1, zeros = 0, ans = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        if (first == -1) {
          ans += a;
          first = 0;
        } else {
          ans += min(a, b * zeros);
        }
        zeros = 0;
      } else {
        ++zeros;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
