#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e, long long m) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    string ss;
    cin >> ss;
    long long n = ss.length();
    string s = "";
    long long ind = -1;
    for (long long i = 0; i < n; i++)
      if (ss[i] == '1') {
        ind = i;
        break;
      }
    if (ind == -1) {
      cout << "0"
           << "\n";
      continue;
    }
    long long ind2 = -1;
    for (long long i = n - 1; i >= 0; i--)
      if (ss[i] == '1') {
        ind2 = i;
        break;
      }
    for (long long i = ind; i <= ind2; i++) s += ss[i];
    n = s.length();
    long long c = 0;
    long long ans = a;
    for (long long i = 0; i < n - 1; i++) {
      if (s[i] == '0' && s[i + 1] == '1') {
        c++;
        if (b * c <= a) {
          ans += (b * c);
        } else {
          ans += a;
        }
        c = 0;
      } else if (s[i] == '0')
        c++;
    }
    cout << ans << "\n";
  }
  return 0;
}
