#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int t, n;
int dp[maxn];
int main() {
  t = read();
  while (t--) {
    string s;
    int a, b, last = -2;
    a = read();
    b = read();
    memset(dp, 0, sizeof(dp));
    cin >> s;
    for (register int i = 1; i <= s.length(); i++) {
      if (s[i - 1] == '0')
        dp[i] = dp[i - 1];
      else {
        if (last == -2)
          dp[i] = dp[i - 1] + a;
        else
          dp[i] = min(dp[i - 1] + a, dp[last + 1] + (i - 2 - last) * b);
        last = i - 1;
      }
    }
    write(dp[s.length()]);
    printf("\n");
  }
  return 0;
}
