#include <bits/stdc++.h>
using namespace std;
int a, b, m;
string s;
long long int dp[100001][2];
long long int fun(long long int n, long long int k) {
  if (n == m) return (k ? a : 0);
  if (dp[n][k] != -1) return dp[n][k];
  long long int ans;
  if (k) {
    if (s[n] == '1')
      ans = fun(n + 1, 1);
    else
      ans = min(a + fun(n + 1, 0), b + fun(n + 1, 1));
  } else {
    if (s[n] == '1')
      ans = fun(n + 1, 1);
    else
      ans = fun(n + 1, 0);
  }
  return dp[n][k] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    cin >> s;
    m = s.length();
    for (long long int i = 0; i < m; i++) dp[i][0] = dp[i][1] = -1;
    long long int res = fun(0, 0);
    cout << res << "\n";
  }
  return 0;
}
