#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long tc;
  cin >> tc;
  while (tc--) {
    long long a, b, cnt = 0;
    cin >> a >> b;
    string s;
    cin >> s;
    s = '0' + s;
    long long st = a / b;
    long long l = 0, r = s.size() - 1;
    while (s[l] == '0' && l < s.size()) l++;
    while (s[r] == '0' && r >= 0) r--;
    long long gap = 0, ans = a;
    vector<long long> as;
    for (; l <= r; l++) {
      if (s[l] == '1' && s[l - 1] == '0') {
        ans += min(a, gap * b);
        if (gap != 0) as.push_back(gap);
        gap = 0;
        cnt++;
      } else if (s[l] == '0')
        gap++;
    }
    if (gap != 0) as.push_back(gap);
    if (as.size() != 0 || cnt != 0)
      cout << ans << endl;
    else
      cout << "0" << endl;
  }
}
