#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  int n = s.size();
  int cost = 0;
  int i = 0;
  while (s[i] == '0' && i < n) i++;
  if (i == n) {
    cout << 0 << endl;
    return;
  }
  while (i < n) {
    if (s[i] == '0' && i < n) {
      int l = 0;
      while (s[i] == '0') {
        i++;
        l++;
      }
      if (i < n) {
        if (b * l < a)
          cost += b * l;
        else
          cost += a;
      }
    } else {
      while (s[i] == '1' && i < n) i++;
    }
  }
  cost += a;
  cout << cost << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
