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