#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k, t, sum = 0, a, b, p;     cin >> t;     while (t--) {       bool fg = 0;       p = 0;       k = 0;       sum = 0;       cin >> a >> b;       string s;       cin >> s;       n = s.size();       for (long long int i = 0; i <= n - 1; i++) {         if (s[i] ==  1 ) {           if (fg == 0) {             p += a;             fg = 1;             k = 0;           } else if (k > 0) {             p += min(k * b, a);             k = 0;             continue;           }         } else           k++;       }       cout << p << endl;     }     return 0;   }   