#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int len = s.size();
    int dp[len];
    int count = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '1') {
        count++;
        if (i == len - 1 || s[i + 1] == '0') {
          dp[i] = count;
        } else
          dp[i] = 0;
      } else {
        dp[i] = 0;
        count = 0;
      }
    }
    int pre = -1;
    for (int j = 0; j < len; j++) {
      if (dp[j] == 0) continue;
      if (pre == -1) {
        dp[j] = a;
        pre = j;
      } else {
        int l = (j - pre - dp[j]) * b + dp[pre];
        int r = a + dp[pre];
        if (l <= r)
          dp[j] = l;
        else
          dp[j] = r;
        pre = j;
      }
    }
    if (pre == -1)
      cout << 0 << endl;
    else
      cout << dp[pre] << endl;
    t--;
  }
  return 0;
}
