#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exponent) {
  long long res = 1;
  while (exponent > 0) {
    if (exponent & 1) {
      res = (base * res) % 1000000007;
    }
    base = (base * base) % 1000000007;
    exponent /= 2;
  }
  return res;
}
long long modMul(long long a, long long b) { return (a * b) % 1000000007; }
long long modAdd(long long a, long long b) { return (a + b) % 1000000007; }
long long modSub(long long a, long long b) { return (a - b) % 1000000007; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    vector<long long> freq;
    long long flag = 0;
    long long n = s.length();
    for (long long i = 0; i < n; i++) {
      if (s[i] == '1') {
        flag = 1;
      }
      if (flag == 0) continue;
      long long j = i;
      long long cnt = 0;
      while (j < n && s[j] == s[i]) {
        cnt++;
        j++;
      }
      freq.push_back(cnt);
      if (cnt > 0) {
        i = i + cnt - 1;
      }
    }
    if (freq.size() == 0) {
      cout << "0\n";
      continue;
    }
    long long cost = 0;
    long long h = freq.size();
    if (s[s.length() - 1] == '0') {
      h = freq.size() - 1;
    }
    for (long long i = 1; i < h; i += 2) {
      if (freq[i] * b <= a) {
        cost += (freq[i] * b);
        freq[i] = 1;
      } else
        freq[i] = 0;
    }
    long long comp = 0;
    for (long long i = 0; i < h; i++) {
      if (freq[i] == 0) comp++;
    }
    comp++;
    cout << comp * a + cost << "\n";
  }
  return 0;
}
