#include <bits/stdc++.h>
char s[100001];
int main() {
  register int t, n, a, b, ans, lst;
  for (scanf("%d", &t); t--; printf("%d\n", ans)) {
    scanf("%d%d%s", &a, &b, s);
    ans = 0;
    lst = -999999;
    for (register int i = 0; s[i]; ++i)
      if (s[i] ^ '0')
        ans += ((a) < (b * (i - lst - 1)) ? (a) : (b * (i - lst - 1))), lst = i;
  }
}
