#include <bits/stdc++.h>
using namespace std;
char in[100000] = {0};
long long check[100000] = {0};
int main() {
  long t;
  cin >> t;
  while (t--) {
    int a, b, cnt = 0, cnb = 0;
    cin >> a >> b;
    cin >> in;
    for (int i = 0; in[i] != 0; i++) {
      if (cnt == 0 && in[i] == '0') continue;
      if (cnt == 0 && in[i] == '1') {
        check[cnt] = a;
        cnt++;
        continue;
      }
      if (cnb == 0 && in[i] == '1') {
        continue;
      }
      if (in[i] == '0') {
        cnb++;
        continue;
      }
      if (cnb && in[i] == '1') {
        check[cnt] = cnb * b;
        cnb = 0;
        cnt++;
        check[cnt] = a;
        cnt++;
        continue;
      }
    }
    long long sum = (cnt + 1) / 2 * a;
    for (int i = 0; i < cnt; i++) {
      if (i % 2) {
        if (check[i] < a) sum = sum + check[i] - a;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
