#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int OFF = (1 << 20);
int t, a, b;
string s;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b;
    cin >> s;
    int p = 0;
    while (p < s.size() && s[p] == '0') p++;
    if (p == s.size())
      cout << "0\n";
    else {
      int sol = a;
      while (p < s.size()) {
        while (p < s.size() && s[p] == '1') p++;
        int kol = 0;
        while (p < s.size() && s[p] == '0') p++, kol++;
        if (p < s.size()) sol += min(kol * b, a);
      }
      cout << sol << "\n";
    }
  }
  return 0;
}
