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