#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
string s;
int a, b, n, L[maxn], R[maxn], res;
int main() {
  int test;
  cin >> test;
  while (test--) {
    cin >> a >> b >> s;
    s += '0';
    n = 0;
    int i = 0;
    while (i < s.size()) {
      if (s[i] == '0') {
        ++i;
        continue;
      }
      ++n;
      L[n] = i;
      while (s[i] == '1') ++i;
      R[n] = i - 1;
    }
    if (n == 0) {
      cout << 0 << '\n';
      continue;
    }
    res = a;
    for (int i = 2; i <= n; ++i) res += min(a, (L[i] - R[i - 1] - 1) * b);
    cout << res << '\n';
  }
  return 0;
}
