#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		if (n > 2) {
			int zero = count(all(s), '0');
			if (s[0] == '0')zero--;
			if (s[n - 1] == '0')zero--;

			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1')br;
				cnt1++;
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')br;
				cnt2++;
			}
			// int ans = 0;
			if (cnt1 > 0)cnt1--;
			if (cnt2 > 0)cnt2--;
			// ans += (cnt2 + cnt1) * b;
			zero -= (cnt1 + cnt2);
			int ans = INT_MAX;
			FOR(i, 0, zero + 1) {
				ans = min(ans, i * b + (zero - i + 1) * a);
			}
			// int P1 = (zero + 1) * a;
			// int P2 = zero * b + a;
			// cout << max(0, min(P1, P2)) << endl;
			cout << ans << endl;
		}
		else{
			int t1 = 0, t2 = 0;
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		if (n > 2) {
			int one = count(all(s), '1'), zero = count(all(s), '0');
			if (s[0] == '0')zero--;
			if (s[n - 1] == '0')zero--;

			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1')br;
				cnt1++;
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')br;
				cnt2++;
			}
			int ans = 0;
			if (cnt1 > 0)cnt1--;
			if (cnt2 > 0)cnt2--;
			ans += (cnt2 + cnt1) * b;
			zero -= (cnt1 + cnt2);
			int P1 = one * a;
			int P2 = zero * b + a;
			cout << ans + min(P1, P2) << endl;
		}
		else{
			int t1 = 0, t2 = 0;
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << b + a << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << a + b << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int j = s.length() - 1, i = 0;
		while (i != s.length() && s[i] == '0')i++;
		if (i == s.length())cout << "0\n";
		else{
			while (s[j] == '0') {
				j--;
			}

			vi p;
			int k = i;
			while (k < j) {
				if (s[k] == '1')k++;
				else {
					int l = k;
					while (s[l] == '0')l++;
					p.pb(l - k);
					k = l;
				}
			}
			int cnt = a * (p.size() + 1);
			FOR(k, 0, p.size()) {
				if (b * p[k] < a) {cnt -= a; cnt += b * p[k];}
			}
			// FOR(i, 0, p.size())cout << p[i].FF << " " << p[i].SS << endl;
			cout << cnt << endl;}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		if (n > 2) {
			int one = count(all(s), '1'), zero = count(all(s), '0');
			if (s[0] == '0')zero--;
			if (s[n - 1] == '0')zero--;

			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1')br;
				cnt1++;
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')br;
				cnt2++;
			}
			int ans = 0;
			if (cnt1 > 0)cnt1--;
			if (cnt2 > 0)cnt2--;
			ans += (cnt2 + cnt1) * b;
			zero -= (cnt1 + cnt2);
			int P1 = one * a;
			int P2 = zero * b + a;
			cout << ans + min(P1, P2) << endl;
		}
		else{
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << b + 1 << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << a + b << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		if (n > 2) {
			int one = count(all(s), '1'), zero = count(all(s), '0');
			if (s[0] == '0')zero--;
			if (s[n - 1] == '0')zero--;

			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1')br;
				cnt1++;
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')br;
				cnt2++;
			}
			// int ans = 0;
			if (cnt1 > 0)cnt1--;
			if (cnt2 > 0)cnt2--;
			// ans += (cnt2 + cnt1) * b;
			zero -= (cnt1 + cnt2);
			int P1 = one * a;
			int P2 = zero * b + a;
			cout << max(0, min(P1, P2)) << endl;
		}
		else{
			int t1 = 0, t2 = 0;
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		s.pb('0');
		if (n > 2) {
			int zero = 0;
			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1') {
					cnt1 = i; br;
				}
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')
				{
					cnt2 = i;
					br;
				}
			}
			FOR(i, 0, s.length()) {
				if (s[i] == '1' && s[i + 1] == '0')zero++;
			}
			int P1 = (zero) * a;
			int P2 = (count(s.begin() + cnt1, s.begin() + cnt2 + 1, '0')) * b + a;
			cout << max(0, min(P1, P2)) << endl;
		}
		else{
			int t1 = 0, t2 = 0;
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		if (n > 2) {
			int one = count(all(s), '1'), zero = count(all(s), '0');
			if (s[0] == '0')zero--;
			if (s[n - 1] == '0')zero--;

			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1')br;
				cnt1++;
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')br;
				cnt2++;
			}
			int ans = 0;
			if (cnt1 > 0)cnt1--;
			if (cnt2 > 0)cnt2--;
			ans += (cnt2 + cnt1) * b;
			zero -= (cnt1 + cnt2);
			int P1 = one * a;
			int P2 = zero * b + a;
			cout << min(P1, ans + P2) << endl;
		}
		else{
			int t1 = 0, t2 = 0;
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << b + a << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << a + b << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		s.pb('0');
		vec<ii> p;
		int cnt = 0;
		FOR(i, 0, s.length()) {
			if (s[i] == '1') {
				FOR(j, i, s.length()) {
					if (s[j] == '0') {
						p.pb({i, j - 1});
						i = j - 1;
						br;
					}
				}
			}
		}
		if (p.size() > 0) {
			FOR(i, 0, p.size() - 1) {
				if (b * (p[i + 1].FF - p[i].SS - 1) <= a) {
					cnt += b * (p[i + 1].FF - p[i].SS - 1);
				}

			}
		}
		if (cnt == 0)cnt += p.size() * a;
		else
			cnt += a;
		// FOR(i, 0, p.size())cout << p[i].FF << " " << p[i].SS << endl;
		cout << cnt << endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = s.length();
		s.pb('0');
		if (n > 2) {
			int zero = 0;
			int cnt1 = 0, cnt2 = 0;
			FOR(i, 0, n) {
				if (s[i] == '1') {
					cnt1 = i; br;
				}
			}
			ROF(i, n - 1, 0) {
				if (s[i] == '1')
				{
					cnt2 = i;
					br;
				}
			}
			FOR(i, 0, s.length()) {
				if (s[i] == '1' && s[i + 1] == '0')zero++;
			}
			int P1 = (zero) * a;
			int P2 = (zero - 1) * b + a;
			cout << max(0, min(P1, P2)) << endl;
		}
		else{
			int t1 = 0, t2 = 0;
			if (n == 1) {
				if (s[0] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			if (n == 2) {
				if (s[0] == '1' || s[1] == '1')cout << a << endl;
				else cout << "0" << endl;
			}
			// cout << one << " " << zero << endl;
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	testcases{
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int j = s.length() - 1, i = 0;
		while (i != s.length() && s[i] == '0')i++;
		if (i == s.length())cout << "0\n";
		else{
			while (s[j] == '0') {
				j--;
			}

			vi p;
			int k = i;
			while (k < j) {
				if (s[k] == '1')k++;
				else {
					int l = k;
					while (s[l] == '0')l++;
					p.pb(l - k);
					k = l;
				}
			}
			int cnt = a * (p.size() + 1);
			FOR(k, 0, p.size()) {
				if (b * p[k] < a) {cnt -= a; cnt += b * p[k];}
			}

			cout << cnt << "\n";}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0;
        n = zeroes.size();
        int prev = n;
        int ct = 0;
        for (int i = 0; i < n; i++)
        {
            consec += zeroes[i];
            if (consec * b <= a)
            {
                if (i == n - 1)
                {
                    cost += consec * b + a;
                }
            }
            else
            {
                consec -= zeroes[i];
                if (consec)
                    cost += consec * b + a;
                if (zeroes[i] * b > a)
                {
                    cost += a;
                    if (i == n - 1)
                        cost += a;
                    consec = 0;
                }
                else
                {
                    i--;
                }
                consec = 0;
            }
        }
        if (!n)
        {
            cost += a;
        }
        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = a * (zeroes.size() + 1), consec = 0, ct = 0, f = 0;
        n = zeroes.size();
        for (int i = 0; i < n; i++)
        {
            if (zeroes[i] * b < a)
            {
                cost -= a;
                cost += zeroes[i] * b;
            }
        }

        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0;
        n = zeroes.size();
        int prev = n;
        int ct = 0;
        for (int i = 0; i < n; i++)
        {
            consec += zeroes[i];
            if (consec * b <= a)
            {
                if (i == n - 1)
                {
                    cost += consec * b + a;
                }
            }
            else
            {
                consec -= zeroes[i];
                cost += consec * b + a;
                if (zeroes[i] * b > a)
                {
                    // cost += a;
                    consec = 0;
                }
                else
                {
                    i--;
                }
                consec = 0;
            }
        }

        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0, ct = 0, f = 0;
        n = zeroes.size();
        if (n)
            cost = a * (zeroes.size() + 1);
        for (int i = 0; i < n; i++)
        {
            if (zeroes[i] * b < a)
            {
                cost -= a;
                cost += zeroes[i] * b;
            }
        }
        if (!n && s[0] == '1')
            cost = a;
        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0;
        n = zeroes.size();
        int prev = n;
        int ct = 0;
        for (int i = 0; i < n; i++)
        {
            consec += zeroes[i];
            if (consec * b <= a)
            {
                if (i == n - 1)
                {
                    cost += consec * b + a;
                }
            }
            else
            {
                consec -= zeroes[i];
                if (consec)
                    cost += consec * b + a;
                if (zeroes[i] * b > a)
                {
                    cost += a;
                    if (i == n - 1)
                        cost += a;
                    consec = 0;
                }
                else
                {
                    i--;
                }
                consec = 0;
            }
        }
        if (!n && s[i] == '1')
        {
            cost += a;
        }
        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0, ct = 0, f = 0;
        n = zeroes.size();
        for (int i = 0; i < n; i++)
        {
            // consec += zeroes[i];
            while (i < n && zeroes[i] * b <= a)
            {
                f = 1;
                cost += zeroes[i] * b;
                i++;
            }

            ct++;
        }
        if (n == 1 && !f)
        {
            ct++;
        }
        if (n == 0)
        {
            if (s[0] == '1')
                cost = a;
        }
        cost += a * ct;
        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size();
        int x1 = 0, y0 = 0;
        int cost = 0, pos1 = -1, last;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '1')
            {
                if (pos1 == -1)
                    pos1 = i;
                else
                {
                    y0 = i - 1 - pos1;
                    if (y0)
                    {
                        cost += min(2 * a, y0 * b + a);
                        pos1 = -1;
                        while (i + 1 < n && s[i + 1] == '1')
                            i++;
                        last = i + 1;
                    }
                    else
                    {
                        pos1 = i;
                    }
                }
            }
        }
        int f = 0;
        for (int i = last; i < n; i++)
        {
            if (s[i] == '1')
                f = 1;
        }
        if (f)
            cost += min(a, b + a);
        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0;
        n = zeroes.size();
        int prev = n;
        int ct = 0;
        for (int i = 0; i < n; i++)
        {
            consec += zeroes[i];
            if (consec * b <= a)
            {
                if (i == n - 1)
                {
                    cost += consec * b + a;
                }
            }
            else
            {
                consec -= zeroes[i];
                if (consec)
                    cost += consec * b + a;
                if (zeroes[i] * b > a)
                {
                    cost += a;
                    if (i == n - 1)
                        cost += a;
                    consec = 0;
                }
                else
                {
                    i--;
                }
                consec = 0;
            }
        }

        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
long long int mem[5001] = {INT_MIN};
ll int ct = 0;

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    ll int t;
    cin >> t;
    while (t--)
    {
        ll int a, b;
        string s;
        cin >> a >> b;
        cin >> s;
        int n = s.size(), last;
        vector<int> zeroes;
        int k = 0;
        while (s[k] == '0')
        {
            k++;
        }
        s = s.substr(k);
        n = s.size();
        k = n - 1;
        while (s[k] == '0')
        {
            k--;
            n--;
        }
        s = s.substr(0, n);
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '0')
            {
                last = i;
                while (i + 1 < n && s[i + 1] != '1')
                    i++;
                zeroes.push_back(i - last + 1);
            }
        }
        int cost = 0, consec = 0;
        n = zeroes.size();
        int prev = n;
        int ct = 0;
        for (int i = 0; i < n; i++)
        {
            consec += zeroes[i];
            if (consec * b <= a)
            {
                if (i == n - 1)
                {
                    cost += consec * b + a;
                }
            }
            else
            {
                consec -= zeroes[i];
                if (consec)
                    cost += consec * b + a;
                if (zeroes[i] * b > a)
                {
                    cost += a;
                    if (i == n - 1)
                        cost += a;
                    consec = 0;
                }
                else
                {
                    i--;
                }
                consec = 0;
            }
        }
        if (!n && s[0] == '1')
        {
            cost += a;
        }
        cout << cost << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
const int N=100005;
int dp[N], a, b;
vector<int>v;

int fun(int pos)
{
    if(pos==v.size()) return a;
    if(dp[pos]!=-1) return dp[pos];
    int ans=1e18;
    ans=min(ans, v[pos]*b+fun(pos+1));
    ans=min(ans, a+fun(pos+1));
    return dp[pos]=ans;
}

main()
{
    fastio;
    int t;
    cin>>t;
    while(t--) {
        v.clear();
        string s;
        int st=-1, en=-1, z=0, chk=0;
        cin>>a>>b>>s;
        for(int i=0; i<=s.size(); i++) dp[i]=-1;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='1' && !chk) {
                st=1;
                chk=1;
            }
            if(s[i]=='1') en=i;
        }
        for(int i=st; i<=en; i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        if(st==-1 && en==-1) cout<<"0"<<endl;
        else if(v.size()==0) cout<<a<<endl;
        else cout<<fun(0)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
//const int N=200005;
//int ar[N], b[N], pref[N];

main()
{
    fastio;
    int t, a, b;
    cin>>t;
    while(t--) {
        string s;
        int st, en, z=0;
        vector<int>v;
        cin>>a>>b>>s;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        int sm=0, cnt=2, ans=0;
        if(v.size()<=2) {
            cout<<a<<endl;
        }
        else {
        for(int i=1; i<v.size()-1; i++) {
            if(((sm+v[i])*b+a)<=(cnt)*a) {
                sm+=v[i];
                cnt++;
            }
            else {
                if(cnt==2) ans+=2*a;
                else ans+=sm*b+a;
                cnt=2;
            }
        }
        if(sm) {
            if(cnt==2) ans+=2*a;
            else ans+=sm*b+a;
        }
        cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
//const int N=200005;
//int ar[N], b[N], pref[N];

main()
{
    fastio;
    int t, a, b;
    cin>>t;
    while(t--) {
        string s;
        int st, en, z=0;
        vector<int>v;
        cin>>a>>b>>s;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        int sm=0, cnt=2, ans=0;
        for(int i=1; i<v.size()-1; i++) {
            if(((sm+v[i])*b+a)<=(cnt)*a) {
                sm+=v[i];
                cnt++;
            }
            else {
                if(cnt==2) ans+=2*a;
                else ans+=sm*b+a;
                cnt=2;
            }
        }
        if(sm) {
            if(cnt==2) ans+=2*a;
            else ans+=sm*b+a;
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
const int N=1005;
int dp[N][N], a, b;
vector<int>v;

int fun(int pos, int sm)
{
    if(pos==v.size()) return sm*b+a;
    if(dp[pos][sm]!=-1) return dp[pos][sm];
    int ans=1e18;
    ans=min(ans, fun(pos+1, sm+v[pos]));
    ans=min(ans, sm*b+a+fun(pos+1, 0));
    return dp[pos][sm]=ans;
}

main()
{
    fastio;
    int t;
    cin>>t;
    while(t--) {
        v.clear();
        string s;
        int st=-1, en=-1, z=0, chk=0;
        cin>>a>>b>>s;
        for(int i=0; i<=s.size(); i++) {
            for(int j=0; j<=s.size(); j++) {
                dp[i][j]=-1;
            }
        }
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='1' && !chk) {
                st=1;
                chk=1;
            }
            if(s[i]=='1') en=i;
        }
        for(int i=st; i<=en; i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        if(st==-1 && en==-1) cout<<"0"<<endl;
        else if(v.size()==0) cout<<a<<endl;
        else cout<<fun(0, 0)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
//const int N=200005;
//int ar[N], b[N], pref[N];

main()
{
    fastio;
    int t, a, b;
    cin>>t;
    while(t--) {
        string s;
        int st=-1, en=-1, z=0,chk=0;
        vector<int>v;
        cin>>a>>b>>s;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='1' && !chk) {
                st=1;
                chk=1;
            }
            if(s[i]=='1') en=i;
        }
        for(int i=st; i<=en; i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(st==-1 && en==-1) cout<<"0"<<endl;
        else if(v.size()==0) cout<<a<<endl;
        else {
            if(z) v.pb(z);
            int sm=0, cnt=2, ans=0;
            for(int i=0; i<v.size(); i++) {
                if(((sm+v[i])*b+a)<=(cnt)*a) {
                    sm+=v[i];
                    cnt++;
                }
                else {
                    if(cnt==2) ans+=2*a;
                    else ans+=sm*b+a;
                    cnt=2;
                }
            }
            if(sm) {
                if(cnt==2) ans+=2*a;
                else ans+=sm*b+a;
            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
const int N=100005;
int dp[N], a, b;
vector<int>v;

int fun(int pos)
{
    if(pos==v.size()) return a;
    if(dp[pos]!=-1) return dp[pos];
    int ans=1e18;
    ans=min(ans, v[pos]*b+fun(pos+1));
    ans=min(ans, a+fun(pos+1));
    return dp[pos]=ans;
}

main()
{
    fastio;
    int t;
    cin>>t;
    while(t--) {
        v.clear();
        string s;
        int st=-1, en=-1, z=0, chk=0;
        cin>>a>>b>>s;
        for(int i=0; i<=s.size(); i++) dp[i]=-1;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='1' && !chk) {
                st=i;
                chk=1;
            }
            if(s[i]=='1') en=i;
        }
        for(int i=st; i<=en; i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        if(st==-1 && en==-1) cout<<"0"<<endl;
        else if(v.size()==0) cout<<a<<endl;
        else cout<<fun(0)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
const int N=1005;
int dp[N][N], a, b;
vector<int>v;

int fun(int pos, int sm)
{
    if(pos==v.size()) return sm*b+a;
    if(dp[pos][sm]!=-1) return dp[pos][sm];
    int ans=1e18;
    ans=min(ans, fun(pos+1, sm+v[pos]));
    ans=min(ans, sm*b+a+fun(pos+1, 0));
    return dp[pos][sm]=ans;
}

main()
{
    fastio;
    int t;
    cin>>t;
    while(t--) {
        v.clear();
        memset(dp, -1, sizeof(dp));
        string s;
        int st=-1, en=-1, z=0, chk=0;
        cin>>a>>b>>s;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='1' && !chk) {
                st=1;
                chk=1;
            }
            if(s[i]=='1') en=i;
        }
        for(int i=st; i<=en; i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        if(st==-1 && en==-1) cout<<"0"<<endl;
        else if(v.size()==0) cout<<a<<endl;
        else cout<<fun(0, 0)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define pii make_pair
#define pb push_back
#define ff first
#define ss second
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }
//const int N=200005;
//int ar[N], b[N], pref[N];

main()
{
    fastio;
    int t, a, b, tmp=0;
    cin>>t;
    while(t--) {
        tmp++;
        string s;
        int st=-1, en=-1, z=0,chk=0;
        vector<int>v;
        cin>>a>>b>>s;
        for(int i=0; i<s.size(); i++) {
            if(s[i]=='1' && !chk) {
                st=1;
                chk=1;
            }
            if(s[i]=='1') en=i;
        }
        for(int i=st; i<=en; i++) {
            if(s[i]=='0') z++;
            else {
                if(z) v.pb(z);
                z=0;
            }
        }
        if(z) v.pb(z);
        if(st==-1 && en==-1) cout<<"0"<<endl;
        else if(v.size()==0) cout<<a<<endl;
        else {
            int sm=0, cnt=2, ans=0;
            for(int i=0; i<v.size(); i++) {
                if(((sm+v[i])*b+a)<=(cnt)*a) {
                    sm+=v[i];
                    cnt++;
                }
                else {
                    if(sm) ans+=sm*b+a;
                    else ans+=a;
                    sm=0;
                    cnt=2;
                }
            }
            if(sm) ans+=sm*b+a;
            else ans+=a;
            cout<<ans<<endl;
        }
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }

        vector<int> z;
        fori(i,l,r+1){
            int count = 0;
            if(s[i]== '0'){
                count++;
            }
            else {
                z.push_back(count);
                count = 0;
            }
        }

        sort(z.begin(),z.end());
        int ind = upper_bound(z.begin(),z.end(),a) - z.begin();
        int left = z.size() - ind +1;

        int fans = a + b*left ;
        cout<<fans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }
        s = s+"1";
        bool flag =true;
        int count =  0;
        int l1 = l,r1 = r;
        int ans = 0;
        int z  =0 ;
        fori(i,l,r+1){
            if(s[i]=='0'){
                if(flag){
                    l1 = i;
                    flag = false;
                }
                z++;
                count++;
            }
            else {
                flag = true;
                r1 = i;
                // cout<<count<<endl;
                if(a >  b*count){
                    fori(j,l1,r1){
                        s[j]='1';
                    }
                    ans+=b*count;
                }
                count=0;
            }
            // cout<<s<<endl;
        }
        // cout<<ans<<endl;
        if(z==0){
            cout<<a<<endl;
            continue;
        }
        int c = 0;
        stack<char> st;
        fori(i,l,r+1){
            if(st.size()>0){
                if(st.top()!= s[i]){
                    st.push(s[i]);
                }
            }
            else{
                st.push(s[i]);
            }
        }
        while(!st.empty()){
            if(st.top()=='1'){
                ans+=a;

            }
            st.pop();
        }

        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        bool flag = false;
        int ans = 0;
        int temp=a;
        int l  = 0;
        fori(i,0,n){
            if(s[i]=='1'){
                l = i;
                break;
            }
        }
        fori(i, l ,n){
            if(s[i]=='1'){
                if(!flag && temp){
                    flag = true;
                    ans += min(a,temp);
                }
            }
            else{
                if(flag){
                    flag = false;
                    temp = b;
                }
                else temp+=b;
            }

        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }

        vector<int> z;
        int o = 0;
        int count = 0;
        fori(i,l,r+1){
            if(s[i]== '0'){
                count++;
            }
            else {
                o++;
                if(count!=0)
                z.push_back(count*b);
                count = 0;
            }
        }
        if(o==0){
            cout<<0<<endl;
            continue;
        }

        sort(z.begin(),z.end());
        // out(z,z.size());
        int ind = lower_bound(z.begin(),z.end(),a) - z.begin();
        // cout<<ind<<endl;
        //ind will point to the index which is greater than a
        int left = z.size() - ind ;

        int fans = a + b*ind + a*left;
        cout<<fans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }
        s = s+ "1";
        vector<int> z;
        int o = 0;
        int count = 0;
        fori(i,l,r+1){
            if(s[i]== '0'){
                count++;
            }
            else {
                o++;
                if(count!=0)
                z.push_back(count*b);
                count = 0;
            }
        }
        if(o==0){
            cout<<0<<endl;
            continue;
        }

        sort(z.begin(),z.end());
        // out(z,z.size());
        int ind = lower_bound(z.begin(),z.end(),a) - z.begin();
        // cout<<ind<<endl;
        //ind will point to the index which is greater than a
        int left = z.size() - ind   ;

        int fans = a + b*ind + a*left;
        cout<<fans<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }
        s = s+"1";
        bool flag =true;
        int count =  0;
        int l1 = l,r1 = r;
        int ans = 0;
        fori(i,l,r+1){
            if(s[i]=='0'){
                if(flag){
                    l1 = i;
                    flag = false;
                }

                count++;
            }
            else {
                flag = true;
                r1 = i;
                // cout<<count<<endl;
                if(a >  b*count){
                    fori(j,l1,r1){
                        s[j]='1';
                    }
                    ans+=b*count;
                }
                count=0;
            }
            // cout<<s<<endl;
        }
        // cout<<ans<<endl;
        int c = 0;
        fori(i,l,r+1){
            if(s[i]=='1' && s[i+1]=='0'){
                c++;
            }
        }
        ans+=c*a;

        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }
        s = s+"1";
        bool flag =true;
        int count =  0;
        int l1 = l,r1 = r;
        int ans = 0;
        int z  =0 ;
        fori(i,l,r+1){
            if(s[i]=='0'){
                if(flag){
                    l1 = i;
                    flag = false;
                }
                z++;
                count++;
            }
            else {
                flag = true;
                r1 = i;
                // cout<<count<<endl;
                if(a >  b*count){
                    fori(j,l1,r1){
                        s[j]='1';
                    }
                    ans+=b*count;
                }
                count=0;
            }
            // cout<<s<<endl;
        }
        // cout<<ans<<endl;
        if(z==0){
            cout<<a<<endl;
            continue;
        }
        int c = 0;
        fori(i,l,r+1){
            if(s[i]=='1' && s[i+1]=='0'){
                c++;
            }
        }
        ans+=c*a;

        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }

        bool flag =true;
        int count =  0;
        int l1 = l,r1 = r;
        int ans = 0;
        int z  =0 ;
        fori(i,l,r+1){
            if(s[i]=='0'){
                if(flag){
                    l1 = i;
                    flag = false;
                }
                z++;
                count++;
            }
            else {
                flag = true;
                r1 = i;
                // cout<<count<<endl;
                if(a >  b*count){
                    fori(j,l1,r1){
                        s[j]='1';
                    }
                    ans+=b*count;
                }
                count=0;
            }
            // cout<<s<<endl;
        }
        // cout<<ans<<endl;
        if(z==0){
            cout<<a<<endl;
            continue;
        }
        int c = 0;
        stack<char> st;
        fori(i,0,n){
            if(st.size()>0){
                if(st.top()!= s[i]){
                    st.push(s[i]);
                }
            }
            else{
                st.push(s[i]);
            }
        }
        while(!st.empty()){
            if(st.top()=='1'){
                ans+=a;

            }
            st.pop();
        }

        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }
        s = s+"1";
        bool flag =true;
        int count =  0;
        int l1 = l,r1 = r;
        int ans = 0;
        int z  =0 ;
        fori(i,l,r+1){
            if(s[i]=='0'){
                if(flag){
                    l1 = i;
                    flag = false;
                }
                z++;
                count++;
            }
            else {
                flag = true;
                r1 = i;
                // cout<<count<<endl;
                if(a >  b*count){
                    fori(j,l1,r1){
                        s[j]='1';
                    }
                    ans+=b*count;
                }
                count=0;
            }
            // cout<<s<<endl;
        }
        // cout<<ans<<endl;
        if(z==0){
            cout<<a<<endl;
            continue;
        }
        int c = 0;
        stack<char> st;
        fori(i,0,n){
            if(st.size()>0){
                if(st.top()!= s[i]){
                    st.push(s[i]);
                }
            }
            else{
                st.push(s[i]);
            }
        }
        while(!st.empty()){
            if(st.top()=='1'){
                ans+=a;

            }
            st.pop();
        }

        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }

        bool flag =true;
        int count =  0;
        int l1 = l,r1 = r;
        int ans = 0;
        int z  =0 ;
        fori(i,l,r+1){
            if(s[i]=='0'){
                if(flag){
                    l1 = i;
                    flag = false;
                }
                z++;
                count++;
            }
            else {
                flag = true;
                r1 = i;
                // cout<<count<<endl;
                if(a >= b*count){
                    fori(j,l1,r1){
                        s[j]='1';
                    }
                    ans+=b*count;
                }
                count=0;
            }
            // cout<<s<<endl;
        }
        // cout<<ans<<endl;
        if(z==0){
            cout<<a<<endl;
            continue;
        }
        int c = 0;
        stack<char> st;
        fori(i,0,n){
            if(st.size()>0){
                if(st.top()!= s[i]){
                    st.push(s[i]);
                }
            }
            else{
                st.push(s[i]);
            }
        }
        while(!st.empty()){
            if(st.top()=='1'){
                ans+=a;

            }
            st.pop();
        }

        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]
#define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]
#define out(ar,n) \
    for(int i=0;i<n;i++) \
    cout<<ar[i]<<" "; \
    cout<<endl;
#define swap(a,b)\
    int t = a; \
    a = b; \
    b = t;
#define print(val) cout<<val<<endl;
#define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val
#define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])
#define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])

#define fori(i,a,b) for(ll i=a;i<b;++i)

using namespace std;
typedef  pair<int, int> pi ;
typedef pair<ll,ll> pl;
typedef vector<vector<int>> vvi;
const ll mod = 1e9 + 7;
int main(){
    int t;cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        string s;cin>>s;
        int n =s.size();
        int l  =0 , r = n-1;
        fori(i,0,s.size()){
            if(s[i]=='1'){
                l =  i;
                break;
            }
        }
        for(int  i = n-1;i>=0;i--){
            if(s[i]=='1'){
                r = i;
                break;
            }
        }

        vector<int> z;
        int o = 0;
        int count = 0;
        fori(i,l,r+1){
            if(s[i]== '0'){
                count++;
            }
            else {
                o++;
                if(count!=0)
                z.push_back(count*b);
                count = 0;
            }
        }
        if(o==0){
            cout<<0<<endl;
            continue;
        }

        sort(z.begin(),z.end());
        // out(z,z.size());
        int ind = upper_bound(z.begin(),z.end(),a) - z.begin();
        // cout<<ind<<endl;
        //ind will point to the index which is greater than a
        int left = z.size() - ind ;

        int fans = a + b*ind + a*left;
        cout<<fans<<endl;

    }
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	vii v;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			int cnt = 0;
    			while(l <= r && s[i] == '0')
    			{
    				i++;
    				cnt++;
    			}
    			z++;
    			v.pb(cnt);
    		}
    	}
    	sort(v.begin(), v.end());
    	int ans = 0;
    	for(i = 0; i < v.size(); i++)
    	{
    		if(b*v[i] < a)
    		{
    			ans += b*v[i];
    			o--;
    		}
    		else
    			break;
    	}
    	ans += o*a;
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		int n = (int) s.length();
		vector<int> v;
		for(int i = 0; i < n; i++)
		{
			if(v.empty() or s[i] != s[i - 1])
			{
				v.push_back(1);
			}
			else
			{
				v.back()++;
			}
		}
		int start = s[0] == '0';
		int end = (int) v.size() - 1;
		if(s[n - 1] == 0)
		{
			end--;
		}
		long long sol = 0;
		for(int i = start + 2; i <= end; i += 2)
		{
			if(v[i - 1] * b < a)
			{
				sol += b * v[i - 1];
			}
			else
			{
				sol += a;
			}
			v[i - 1] = v[i - 2] = 0;
		}
		if(start <= end)
		{
			sol += a;
		}
		cout << sol << "\n";
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int l = -1, r = -1;
    	for(i = 0; i < s.size(); i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = s.size()-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	i = l;
    	vii v;
    	int o = 0, z = 0, ans = 0;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			z = 0;
    			while(i <= r && s[i] == '0')
    			{
    				z++;
    				i++;
    			}
    			v.pb(z);
    		}
    	}
    	sort(v.begin(), v.end());
    	for(auto j : v)
    	{
    		if(j*b < a)
    		{
    			ans += j*b;
    			o--;
    		}
    		else
    			break;
    	}
    	ans += o*a;
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	vii v;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			int cnt = 0;
    			while(l <= r && s[i] == '0')
    			{
    				i++;
    				cnt++;
    			}
    			z++;
    			v.pb(cnt);
    		}
    	}
    	sort(v.begin(), v.end());
    	int ans = o*a, tmp = o*a, res = o*a;
    	for(i = 0; i < v.size(); i++)
    	{
    		tmp = (tmp - a) + v[i]*b;
    		if(ans > tmp)
    		{
    			ans = tmp;
    			res = tmp;
    		}
    		else
    		{
    			tmp = res;
    		}
    	}
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	vii v;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			int cnt = 0;
    			while(l <= r && s[i] == '0')
    			{
    				i++;
    				cnt++;
    			}
    			z++;
    			v.pb(cnt);
    		}
    	}
    	sort(v.begin(), v.end());
    	int ans = o*a, tmp = o*a;
    	for(i = 0; i < v.size(); i++)
    	{
    		tmp = (tmp - a) + v[i]*b;
    		ans = min(ans, tmp);
    	}
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l = -1, r = -1;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	vii v;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			int cnt = 0;
    			while(l <= r && s[i] == '0')
    			{
    				i++;
    				cnt++;
    			}
    			z++;
    			v.pb(cnt);
    		}
    	}
    	sort(v.begin(), v.end());
    	int ans = 0;
    	for(i = 0; i < v.size(); i++)
    	{
    		if(b*v[i] < a)
    		{
    			ans += b*v[i];
    			o--;
    		}
    		else
    			break;
    	}
    	ans += o*a;
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	vii v;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			int cnt = 0;
    			while(l <= r && s[i] == '0')
    			{
    				i++;
    				cnt++;
    			}
    			z++;
    			v.pb(cnt);
    		}
    	}
    	// sort(v.begin(), v.end());
    	int ans = o*a, tmp = o*a, res = o*a;
    	for(i = 0; i < v.size(); i++)
    	{
    		tmp = (tmp - a) + v[i]*b;
    		if(ans > tmp)
    		{
    			ans = tmp;
    			res = tmp;
    		}
    		else
    		{
    			tmp = res;
    		}
    	}
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			break;
    		}
    	}
    	l = i;
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			break;
    		}
    	}
    	r = i;
    	for(i = l; i <= r; i++)
    	{
    		o += s[i] == '1' ? 1 : 0;
    		z += s[i] == '0' ? 1 : 0;
    	}
    	cout<<min(o*a, a + z*b)<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			l = i;
    			break;
    		}
    	}
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			r = i;
    			break;
    		}
    	}
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	vii v;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    		{
    			int cnt = 0;
    			while(l <= r && s[i] == '0')
    			{
    				i++;
    				cnt++;
    			}
    			z++;
    			v.pb(cnt);
    		}
    	}
    	sort(v.begin(), v.end());
    	int ans = o*a, tmp = o*a;
    	for(i = 0; i < v.size(); i++)
    	{
    		tmp = (tmp - a) + v[i]*b;
    		if(ans > tmp)
    		{
    			ans = tmp;
    		}
    		else
    		{
    			tmp = (tmp+a) - v[i]*b;
    		}
    	}
    	cout<<ans<<endl;
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define vii             vector<int>
#define vll             vector<ll>
#define mii             map<int, int>
#define mll             map<ll, ll>
#define si              set<int>
#define sl              set<ll>
#define umi             unordered_map<int, int>
#define uml             unordered_map<ll, ll>
#define usi             unordered_set<int>
#define usl             unordered_set<ll>
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define endl            "\n"
#define desc            greater<int>()
#define F               first
#define S               second
#define mod             1000000007
#define pi              3.141592653589793238
#define lcm(a,b)        (a/(__gcd(a,b)))*b
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);

using namespace std;
using namespace __gnu_pbds;

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> PBDS;

int main() {
    FASTIO
    int T = 1;
    cin>>T;
    while(T--)
    {
    	int a, b, i;
    	cin>>a>>b;
    	string s;
    	cin>>s;
    	int o = 0, z = 0;
    	int n = s.size();
    	int l, r;
    	for(i = 0; i < n; i++)
    	{
    		if(s[i] == '1')
    		{
    			break;
    		}
    	}
    	l = i;
    	for(i = n-1; i >= 0; i--)
    	{
    		if(s[i] == '1')
    		{
    			break;
    		}
    	}
    	r = i;
    	for(i = l; i <= r; i++)
    	{
    		z += s[i] == '0' ? 1 : 0;
    	}
    	i = l;
    	while(i <= r)
    	{
    		if(s[i] == '1')
    		{
    			while(i <= r && s[i] == '1')
    				i++;
    			o++;
    		}
    		else
    			i++;
    	}
    	cout<<min(o*a, a + z*b)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;

#define all(x) (x).begin(),(x).end()
#define sz(x) x.size()
#define mp(x,y) make_pair((x),(y))

void solve(){

    int a,b;
    cin>>a>>b;

    string s;
    cin>>s;
    vector<pii> v;
    int i=0;
    int n=sz(s);
    for(;i<n;i++){
        if(s[i]=='1'&& (!i || s[i-1]=='0')){
            int l = i;
            while(s[i]=='1' && i<n)
                i++;

            int r = i-1;
            v.push_back(mp(l,r));
        }
    }
    if(!sz(v))
    {
        cout<<0<<endl;
        return ;
    }
    ll cost=a;
    for(int i=1;i<sz(v);i++){
        if((v[i].first-v[i-1].second-1)*b<a)
            cost+=(v[i].first-v[i-1].second-1)*b;
        else
            cost+=a;
    }
    cout<<cost<<endl;

}

 int  main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int  t;
    cin>>t;
    //t=1;
    while(t--)
        solve();

}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;

#define all(x) (x).begin(),(x).end()
#define sz(x) x.size()

void solve(){

    int a,b;
    cin>>a>>b;

    vector<int> pos;
    string s;
    cin>>s;

    int n=s.size();

    for(int i=0;i<n;i++)
    {
        int x = s[i]-'0';

        if(x)
            pos.push_back(i);
    }

    int N = pos.size();

    if(N==1)
    {
        cout<<a<<endl;
        return;
    }

    vector<int> cost(N,0);

    cost[0] = a;

    for(int i=1;i<N;i++){
        cost[i] = min(b*(pos[i]-pos[i-1]-1)+cost[i-1],a+cost[i-1]);
    }

    cout<<cost[N-1]<<endl;
}

 int  main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int  t;
    cin>>t;
    //t=1;
    while(t--)
        solve();

}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;

#define all(x) (x).begin(),(x).end()
#define sz(x) x.size()
#define mp(x,y) make_pair((x),(y))

void solve(){

    int a,b;
    cin>>a>>b;

    string s;
    cin>>s;
    vector<pii> v;
    int i=0;
    int n=sz(s);
    for(;i<n;i++){
        if(s[i]=='1'&& (!i || s[i-1]=='0')){
            int l = i;
            while(s[i]=='1' && i<n)
                i++;

            int r = i-1;
            v.push_back(mp(l,r));
        }
    }
    if(!sz(v))
    {
        cout<<0<<endl;
        return ;
    }
    ll cost=a;
    for(int i=1;i<sz(v);i++){
        if((v[i].first-v[i-1].second)*b<a)
            cost+=b;
        else
            cost+=a;
    }
    cout<<cost<<endl;

}

 int  main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int  t;
    cin>>t;
    //t=1;
    while(t--)
        solve();

}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;

#define all(x) (x).begin(),(x).end()
#define sz(x) x.size()

int ar[100] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
    31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
void solve(){

    int a,b;
    cin>>a>>b;

    vector<int> pos;
    string s;
    cin>>s;

    int n=s.size();

    for(int i=0;i<n;i++)
    {
        int x = s[i]-'0';

        if(x)
            pos.push_back(i);
    }

    int N = pos.size();

    vector<int> cost(N,0);

    cost[0] = a;

    for(int i=1;i<N;i++){
        cost[i] = min(b*(pos[i]-pos[i-1]-1)+cost[i-1],a+cost[i-1]);
    }

    cout<<cost[N-1]<<endl;
}

 int  main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int  t;
    cin>>t;
    //t=1;
    while(t--)
        solve();

}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;

#define all(x) (x).begin(),(x).end()
#define sz(x) x.size()
#define mp(x,y) make_pair((x),(y))

void solve(){

    int a,b;
    cin>>a>>b;

    string s;
    cin>>s;
    vector<pii> v;
    int i=0;
    int n=sz(s);
    for(;i<n;i++){
        if(s[i]=='1'&& (!i || s[i-1]=='0')){
            int l = i;
            while(s[i]=='1' && i<n)
                i++;

            int r = i-1;
            v.push_back(mp(l,r));
        }
    }
    ll cost=a;
    for(int i=1;i<sz(v);i++){
        if((v[i].first-v[i-1].second)*b<a)
            cost+=b;
        else
            cost+=a;
    }
    cout<<cost<<endl;

}

 int  main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int  t;
    cin>>t;
    //t=1;
    while(t--)
        solve();

}