#include <bits/stdc++.h>
const int T_DATA = 100000;
const int N = 100000;
int T;
int a, b;
char mp[N + 10];
int n, m;
int l[N + 10], r[N + 10];
int dis[N + 10];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &a, &b);
    scanf("%s", mp + 1);
    n = strlen(mp + 1);
    m = 0;
    for (int i = 1, j; i <= n; i = j + 1) {
      while (i <= n && mp[i] != '1') ++i;
      if (i > n) break;
      for (j = i; j < n && mp[j + 1] == '1'; ++j)
        ;
      ++m;
      l[m] = i, r[m] = j;
    }
    if (m == 0) {
      printf("0\n");
      continue;
    }
    if (m == 1) {
      printf("%d\n", a);
      continue;
    }
    for (int i = 1; i <= m - 1; ++i) dis[i] = l[i + 1] - r[i] - 1;
    std::sort(dis + 1, dis + m);
    int ans = a * m;
    for (int ind = 1; ind <= m - 1; ++ind) {
      if (dis[ind] * b >= a) continue;
      ans -= a - dis[ind] * b;
    }
    printf("%d\n", ans);
  }
  return 0;
}
