#include <bits/stdc++.h>
using namespace std;
int t, a, b, tot = 0;
long long ans;
int f[1000005];
string str;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b;
    cin >> str;
    tot = 0;
    ans = 0;
    memset(f, 0, sizeof(f));
    char pre = str[0];
    for (int i = 0; i < str.length(); ++i) {
      if (str[i] == pre) {
        f[tot] += str[i] == '0' ? -1 : 1;
      } else {
        pre = str[i];
        f[++tot] += str[i] == '0' ? -1 : 1;
      }
    }
    int i = f[0] < 0 ? 1 : 0;
    if (f[tot] < 0) tot--;
    for (i; i <= tot;) {
      if (f[i] > 0) {
        ans += a;
        i++;
      } else {
        if (f[i] * -1 * b < a) {
          ans += f[i] * -1 * b;
          i += 2;
        } else {
          i++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
