#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, i, j;
  long long int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  n = s.length();
  long long int c = 0;
  long long int ac = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '1') {
      c++;
      for (j = i + 1; j < n; j++) {
        if (s[i] == '1') {
          i++;
        } else
          break;
      }
    }
  }
  long long int check = 0, check2 = 0;
  vector<long long int> z;
  long long int ch = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '1' && check == 0)
      check = 1;
    else if (s[i] == '1' && check2) {
      z.push_back(ch);
      ch = 0;
      check2 = 0;
    }
    if (s[i] == '0' && check) {
      check2 = 1;
      ch++;
    }
  }
  long long int cost = c * a;
  sort(z.begin(), z.end());
  for (i = 0; i < z.size(); i++) {
    if (cost - a + z[i] * b < cost) {
      cost = cost - a + z[i] * b;
    } else
      break;
  }
  cout << cost << endl;
}
int main() {
  long long int t, i;
  for (i = 0; i < 100000; i++)
    ;
  for (i = 0; i < 100000; i++)
    ;
  for (i = 0; i < 100000; i++)
    ;
  for (i = 0; i < 100000; i++)
    ;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
