#include <bits/stdc++.h>
using namespace std;
long long t, m, k, c, n, x, a, b;
const int mxn = 2e5 + 5;
long long mx = 0, mn = 1e18;
long long arr[300000], ar[300000];
long double y;
char ch;
string str, str2, str3;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> a >> b;
    cin >> str;
    bool zo = 0, on = 0;
    long long couna = 0, ans = 0;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == '1') {
        if (zo) {
          if (b * couna <= a)
            ans += b * couna;
          else
            ans += a;
          couna = 0;
        }
        on = true, zo = false;
      }
      if (str[i] == '0' && on || str[i] == '0' && zo) couna++, zo = true;
    }
    if (on) ans += a;
    cout << ans << endl;
  }
  return 0;
}
