#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t) {
    t--;
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    while (s.back() == '0') s.pop_back();
    reverse(s.begin(), s.end());
    while (s.back() == '0') s.pop_back();
    int i, n = s.size();
    vector<int> v;
    for (i = 1; i < n; i++) {
      if (s[i - 1] == '1' && s[i] == '0')
        v.push_back(1);
      else if (s[i] == '0')
        v.back()++;
    }
    if (s.size() == 0) {
      cout << 0 << endl;
    } else {
      int ans = 0, num = v.size() + 1;
      for (i = 0; i < v.size(); i++) {
        if (v[i] * b <= a) ans += v[i] * b, num--;
      }
      cout << ans + num * a << endl;
    }
  }
}
