#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MAXN = 105;
int main() {
  long long T;
  cin >> T;
  while (T--) {
    long long a, b, n;
    string s;
    cin >> a >> b >> s;
    n = s.size();
    s = " " + s;
    long long ok = 0, ans = 0, sl = 0;
    for (long long i = 1; i <= n; i++) {
      if (s[i] == '0') {
        long long l = 1;
        while (s[i + 1] == '0' && i + 1 <= n) {
          i++;
          l++;
        }
        if (i + 1 <= n && ok) {
          if (a <= l * b) {
            sl++;
          } else {
            ans += l * b;
          }
        }
      } else {
        ok = 1;
      }
    }
    if (ok) sl++;
    ans = ans + sl * a;
    cout << ans << endl;
  }
}
