#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 0;
  cin >> t;
  while (t--) {
    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;
    int n = s.length();
    int x = 0, y = 0, c = 0, f = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1' && f == 0) {
        if (x * b > a || y == 0)
          c += a;
        else
          c += b * x;
        x = 0;
        y = 1;
        f = 1;
      }
      if (s[i] == '0') f = 0, x++;
    }
    cout << c << endl;
  }
  return 0;
}
