#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int a, b, i, j;
    cin >> a >> b;
    string s;
    cin >> s;
    long long int n = s.length();
    std::vector<long long int> v;
    long long int prev = -1, ans = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '1') {
        if (prev == -1)
          prev = i;
        else {
          long long int x = i - prev - 1;
          if (x != 0) {
            if (b * x < a)
              ans += b * x;
            else
              ans += a;
          }
          prev = i;
        }
      }
    }
    if (prev != -1) ans += a;
    cout << ans << "\n";
  }
  cerr << "Time Taken:" << (float)clock() / CLOCKS_PER_SEC * 1000 << "ms"
       << "\n";
  return 0;
}
