#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
void testcase() {
  ll a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  int n = s.length(), last = n + 10;
  vector<ll> dp(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (last >= n) {
        dp[i] = a;
      } else {
        dp[i] = min(dp[last] + a, dp[last] + b * (last - i - 1));
      }
      last = i;
    } else {
      dp[i] = (i < n - 1 ? dp[i + 1] : 0);
    }
  }
  cout << dp[0] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    testcase();
  }
}
