#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long int a, b, i;
    string s;
    cin >> a >> b >> s;
    long long int cnt = 0, ans = 0, cnt1 = 0, cnt0 = 0;
    vector<long long int> res;
    s += '0';
    for (long long int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        cnt1++;
        if (cnt && cnt0) {
          res.push_back(cnt0);
        }
        cnt0 = 0;
      } else {
        cnt0++;
        if (cnt1) {
          cnt++;
        }
        cnt1 = 0;
      }
    }
    if (cnt) ans += a;
    for (long long int i = 0; i < res.size(); i++) {
      ans += min(a, b * res[i]);
    }
    cout << ans << endl;
  }
  cerr << "time taken : " << (float)clock() / (float)CLOCKS_PER_SEC << " secs"
       << endl;
  return 0;
}
