#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  for (scanf("%d", &t); t--;) {
    int a, b;
    char str[100006];
    scanf("%d%d%s", &a, &b, str);
    bool peaceful = true;
    int distance = 0;
    long long r = 0;
    for (int i = 0; str[i]; i++) {
      if (str[i] == '1') {
        if (peaceful) {
          r += a;
          peaceful = false;
        } else if (!distance)
          ;
        else
          r += min(1LL * distance * b, 1LL * a);
        distance = 0;
      } else {
        if (peaceful)
          ;
        else
          distance++;
      }
    }
    printf("%lld\n", r);
  }
}
