#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 100005;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    long long int n = s.length();
    long long int start = 0, end = n - 1;
    long long int f = 0;
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '1') f = 1;
      if (s[i] == '1') {
        start = i;
        break;
      }
    }
    for (long long int i = n - 1; i >= 0; i--) {
      if (s[i] == '1') {
        end = i;
        break;
      }
    }
    if (f == 0) {
      cout << 0 << "\n";
      continue;
    }
    long long int one = 0, zero = 0;
    long long int sum = a;
    long long int flag = 0;
    for (long long int i = start; i <= end;) {
      if (s[i] == '1') {
        zero = 0;
        while (s[i] == '1' && i <= end) i++;
        while (s[i] != '1' && i <= end) {
          i++;
          zero++;
        }
        sum += min(zero * b, a);
      } else
        i++;
    }
    long long int val = sum;
    cout << val << "\n";
  }
  return 0;
}
