#include <bits/stdc++.h>
using namespace std;
char s[100009];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long a, b;
    scanf("%lld %lld %s", &a, &b, s);
    long long last = -1002, ans = 0;
    for (long long i = 0; s[i]; i++) {
      if (s[i] == '1') {
        ans += min(a, b * (i - last - 1));
        last = i;
      }
    }
    printf("%lld\n", ans);
  }
}
