#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t, n, a, b, ans, cnt, pre;
  string s;
  cin >> t;
  while (t--) {
    cin >> a >> b >> s;
    n = s.length();
    ans = pre = cnt = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        if (cnt > 0 && pre > 0) {
          ans += min(a, b * cnt);
        }
        cnt = 0;
        pre++;
      } else
        cnt++;
    }
    if (pre > 0) ans += a;
    cout << ans << endl;
  }
  return 0;
}
