#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const double eps = 1e-9;
const long long inf = 1e18;
int T;
int n, m;
long long a, b;
char ch[maxn];
vector<int> vec;
int main() {
  scanf("%d", &T);
  while (T--) {
    vec.clear();
    scanf("%lld%lld%s", &a, &b, ch + 1);
    n = strlen(ch + 1);
    for (int i = 1; i <= n; i++) {
      if (ch[i] - '0') vec.push_back(i);
    }
    m = vec.size();
    if (m <= 1) {
      printf("%lld\n", a * m);
      continue;
    }
    long long ans = 1;
    for (int i = 1; i < m; i++) {
      if (vec[i] - vec[i - 1] > 1) ans++;
    }
    long long d = ans * a, num = 0;
    for (int i = 1; i < m; i++) {
      if (vec[i] - vec[i - 1] > 1) {
        num = (vec[i] - vec[i - 1] - 1) * b;
        if (num < a) d = d - a + num;
      }
    }
    printf("%lld\n", d);
  }
  return 0;
}
