#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
const int LG = (int)log2(MX) + 1;
const int BLOCK = 205;
const int inf = 1000000069;
const long long inf_ll = 8000000000000000069ll;
const long long mod = 1e9 + 7;
const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1};
const int dx[] = {0, 1, 0, -1, 0, 0};
const int dy[] = {1, 0, -1, 0, 0, 0};
const int dz[] = {0, 0, 0, 0, 1, -1};
const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1};
bool untied = 0;
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(string s = "") {
  if (!untied) unsyncIO(), untied = 1;
  if (s.size()) {
    setIn(s + ".in");
    setOut(s + ".out");
  }
}
int main() {
  setIO();
  int tc;
  cin >> tc;
  for (; tc--;) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    while (s.back() == '0') s.pop_back();
    reverse(s.begin(), s.end());
    while (s.back() == '0') s.pop_back();
    if (s.empty()) {
      cout << 0 << "\n";
      continue;
    }
    long long ans = a;
    for (int i = 0; i < s.size(); i++) {
      int cnt = 0;
      while (s[i] == '0') i++, cnt++;
      ans += (a < cnt * b ? a : cnt * b);
    }
    cout << ans << "\n";
  }
  return 0;
}
