#include <bits/stdc++.h>
using namespace std;
long long T, a, b;
char s[100005];
int main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld", &a, &b);
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int i = 1;
    while (s[i] == '0') ++i;
    long long lst1 = i, num1 = 0, num2 = 0, save = 0;
    for (; i <= n; ++i) {
      if (s[i] == '0') {
        int d = 1;
        while (s[i + 1] == '0') ++i, ++d;
        if (i != n) {
          if (b * d < a) {
            num2++;
            save += (a - b * d);
          }
        }
      } else {
        while (s[i + 1] == '1') ++i;
        num1++;
      }
    }
    long long ans = a * num1 - save;
    printf("%lld\n", ans);
  }
  return 0;
}
