#include <bits/stdc++.h>
using namespace std;
char s[100010];
int main() {
  int t, a, b;
  cin >> t;
  while (t--) {
    cin >> a >> b >> s;
    int i, len = strlen(s), cnta = 0, cntb = 0, l = 0, r = 0;
    while (r < len && s[r] == '0') r++;
    if (r < len) cnta = 1;
    l = r;
    while (r < len) {
      while (r < len && s[r] == '1') r++;
      if (r == len) break;
      l = r - 1;
      while (r < len && s[r] == '0') r++;
      if (r == len) break;
      if (2 * a < a + (r - l - 1) * b)
        cnta++;
      else
        cntb += (r - l - 1);
    }
    cout << a * cnta + b * cntb << endl;
  }
}
