#include <bits/stdc++.h>
bool isPrime(long long n) {
  if (n % 2 == 0 || n % 3 == 0) return false;
  if (n <= 1) return false;
  if (n <= 3) return true;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
using namespace std;
void solve() {
  long long a, b;
  cin >> a >> b;
  string str;
  cin >> str;
  ;
  long long ans = a;
  long long n = str.length();
  long long x = n;
  if (count(str.begin(), str.end(), '1') == n)
    cout << a;
  else if (count(str.begin(), str.end(), '0') == n)
    cout << 0;
  else {
    long long i = 0, cnt0 = 0, cnt01 = 1;
    while (str[i] == '0') ++i;
    --n;
    while (str[n] == '0') --n;
    for (; i <= n; ++i) {
      cnt0 = 0;
      while (str[i] == '1') ++i;
      for (; i <= n; ++i) {
        if (str[i] != '0') break;
        ++cnt0;
      }
      if (cnt0 * b >= a)
        ans += a;
      else
        ans += (cnt0 * b);
    }
    cout << ans;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1, tt = 1;
  ;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
