#include <bits/stdc++.h>
using namespace std;
long long a[500009], b[500009];
map<long long, long long> mp;
int main() {
  cin.sync_with_stdio(false);
  long long i, j, k, l, c, v, n, m, r, t, tt;
  long long x1, x2, y1, y2, x3, x4, x5, x6;
  string s, s34, s1, s2, s3;
  cin >> tt;
  while (tt--) {
    cin >> n;
    cin >> m >> s;
    k = s.size();
    l = n / m;
    c = 0;
    v = 0;
    i = 0;
    while (s[i] == '0') {
      i++;
    }
    k = k - 1;
    while (s[k] == '0') {
      k--;
    }
    for (i = 0; i <= k; i++) {
      if (s[i] == '0' && c == 1) {
        r = 0;
        for (i; i <= k; i++) {
          if (s[i] == '1') {
            i--;
            break;
          }
          r++;
        }
        if (r <= l) {
          v += (r * m);
          c = 1;
        } else
          c = 0;
      } else if (c == 0 && s[i] == '1') {
        v += n;
        c = 1;
      }
    }
    cout << v << endl;
  }
}
