#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 3e5 + 5, M = 1e5 + 5;
const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int dp[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i <= n; i++) dp[i] = 0;
    int last = n;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        if (last == n)
          dp[i] = a;
        else {
          dp[i] = dp[last] + min(a, (i - last - 1) * b);
        }
        last = i;
      }
    }
    cout << dp[last] << endl;
  }
  return 0;
}
