#include <bits/stdc++.h>
using namespace std;
void problem_solver() {
  int a, b, one = 0, ind;
  cin >> a >> b;
  string s;
  cin >> s;
  int n = s.length();
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == '1' && s[i + 1] == '0') {
      one++;
      ind = i;
    }
  }
  if (s[n - 1] == '1') {
    one++;
    ind = n - 1;
  }
  int first;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      first = i;
      break;
    }
  }
  int temp, ans = 0;
  for (int i = first; i < ind; i++) {
    temp = 0;
    if (s[i] == '1' && s[i + 1] == '0') {
      i++;
      while (s[i] == '0') {
        temp += 1;
        i++;
      }
      i--;
      if (temp * b < a) {
        ans += temp * b;
        one--;
      }
    }
  }
  ans += one * a;
  cout << ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    problem_solver();
    cout << "\n";
  }
}
