#include <bits/stdc++.h>
using namespace std;
char used[401];
int main() {
  int t;
  cin >> t;
  ++t;
  int a, b;
  string s;
  int ans = 0, dis;
  bool bol = 0;
  while (--t) {
    cin >> a >> b;
    cin >> s;
    bool bol2 = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '1') bol2 = 1;
    }
    if (!bol2) {
      cout << 0 << '\n';
      continue;
    }
    dis = 0, bol = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '1')
        break;
      else
        s[i] = '1';
    }
    for (int i = 0; i < s.size(); ++i) {
      if (bol == 0 && s[i] == '1') {
        if (dis * b < a) {
          ans += dis * b;
          dis = 0;
        } else {
          ans += a;
          dis = 0;
        }
        bol = 1;
      } else if (s[i] == '0') {
        bol = 0;
        ++dis;
      }
    }
    cout << ans + a << '\n';
    ans = 0;
  }
}
