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