#include <bits/stdc++.h>
using namespace std;
int n, m, k, T, ans, cnt, tot;
string s;
int main() {
  cin >> T;
  while (T--) {
    int a, b;
    cin >> a >> b >> s;
    n = s.size();
    int f = 0;
    ans = 0;
    tot = 0;
    for (int i = 0; i < n; ++i) {
      if (!f && s[i] == '1') {
        f = 1;
        ans += a;
        continue;
      }
      if (s[i] == s[i - 1] && s[i] == '1') continue;
      if (s[i] == '1') {
        if (tot * b < a)
          ans += tot * b;
        else
          ans += a;
        tot = 0;
      } else if (f)
        ++tot;
    }
    cout << ans << endl;
  }
  return 0;
}
