#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    vector<int> v;
    string s;
    cin >> s;
    int n = s.size();
    long long int ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0') continue;
      int j = i;
      while (j < n) {
        if (s[j] != s[i]) break;
        j++;
      }
      if (v.size() == 0)
        v.push_back(j - 1);
      else {
        int val = i - v.back() - 1;
        val *= b;
        if (val <= a) {
          v.pop_back();
          ans += val;
          v.push_back(j - 1);
        } else {
          v.push_back(j - 1);
        }
      }
      i = j - 1;
    }
    ans += (int(v.size()) * a);
    cout << ans << '\n';
  }
}
