#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
long long llOO = 0x3f3f3f3f3f3f3f3f;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int n = s.size();
    long long zeros = 0, ones = 0, prev = 0, ans = 0;
    for (int i = 0; i < n;) {
      while (i < n && s[i] == '0') {
        zeros++;
        i++;
      }
      while (i < n && s[i] == '1') {
        ones++;
        i++;
      }
      if (ones) ans += a;
      if (ones && zeros && prev) {
        ans = min(ans - a + zeros * b, ans);
      }
      prev = ones > 0;
      zeros = ones = 0;
    }
    cout << ans << '\n';
  }
}
