#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const long long int modc = 998244353;
inline void debug(string name, int &val) {
  cout << ">" << name << ": " << val << endl;
}
inline void debug(string name, long long int &val) {
  cout << ">" << name << ": " << val << endl;
}
inline void debug(string name, bool &val) {
  cout << ">" << name << ": " << ((val) ? ("true") : ("false")) << endl;
}
inline void debug(string name, vector<int> &vec) {
  cout << ">" << name << ": ";
  for (int i = 0; i < (int)vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}
inline void debug(string name, vector<long long int> &vec) {
  cout << ">" << name << ": ";
  for (int i = 0; i < (int)vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}
inline void debug(string name, string &s) {
  cout << ">" << name << ": " << s << endl;
}
inline void debug(string name, vector<pair<int, int>> &vec) {
  cout << ">" << name << ": ";
  for (int i = 0; i < (int)vec.size(); i++) {
    cout << "[" << vec[i].first << ", " << vec[i].second << "] ";
  }
  cout << endl;
}
inline void debug(string name,
                  vector<pair<long long int, long long int>> &vec) {
  cout << ">" << name << ": ";
  for (int i = 0; i < (int)vec.size(); i++) {
    cout << "[" << vec[i].first << ", " << vec[i].second << "] ";
  }
  cout << endl;
}
inline void debug(string name, map<int, int> &mp) {
  cout << ">" << name << ": ";
  for (auto x : mp) {
    cout << "[" << x.first << "->" << x.second << "] ";
  }
  cout << endl;
}
inline void debug(string name, map<long long int, long long int> &mp) {
  cout << ">" << name << ": ";
  for (auto x : mp) {
    cout << "[" << x.first << "->" << x.second << "] ";
  }
  cout << endl;
}
inline void debug(string name, unordered_map<int, int> &mp) {
  cout << ">" << name << ": ";
  for (auto x : mp) {
    cout << "[" << x.first << "->" << x.second << "] ";
  }
  cout << endl;
}
inline void debug(string name,
                  unordered_map<long long int, long long int> &mp) {
  cout << ">" << name << ": ";
  for (auto x : mp) {
    cout << "[" << x.first << "->" << x.second << "] ";
  }
  cout << endl;
}
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_cases = 1;
  while (test_cases--) solve();
  return 0;
}
void solve() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    long long int ans = 0;
    int l, r;
    l = 0;
    r = 0;
    vector<int> temp;
    while (r < s.size()) {
      while (r < s.size() && s[l] == s[r]) {
        r++;
      }
      if (s[l] == '0') {
        temp.push_back(r - l);
      } else {
        temp.push_back(-1);
      }
      l = r;
    }
    if (temp.back() != -1) {
      temp.pop_back();
    }
    int index = 0;
    if (temp[0] != -1) index++;
    if (index < temp.size()) {
      ans += a;
    }
    index++;
    while (index < temp.size()) {
      if (temp[index] * b < a) {
        ans += temp[index] * b;
        index += 2;
      } else {
        ans += a;
        index += 2;
      }
    }
    cout << ans << endl;
  }
}
