#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
char s[maxn];
pair<int, int> seg[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    cin >> s;
    int len = strlen(s);
    int cnt = 0;
    long long ans = 0;
    for (int i = 0; i < len; i++)
      if (s[i] == '1') {
        int l = i;
        while (s[i] == '1' && i < len) i++;
        seg[++cnt] = make_pair(l, i - 1);
      }
    if (cnt == 1) {
      cout << a << "\n";
      continue;
    }
    ans = a * cnt;
    for (int i = 1; i < cnt; i++) {
      int r = seg[i].second, l = seg[i + 1].first;
      if (b * (l - r - 1) <= a) ans -= a - b * (l - r - 1);
    }
    cout << ans << '\n';
  }
  return 0;
}
