Bertown is a city with $n$ buildings in a straight line.

The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $n$, where the $i$-th character is "1" if there is a mine under the building number $i$ and "0" otherwise.

Bertown's best sapper knows how to activate mines so that the buildings above them are not damaged. When a mine under the building numbered $x$ is activated, it explodes and activates two adjacent mines under the buildings numbered $x-1$ and $x+1$ (if there were no mines under the building, then nothing happens). Thus, it is enough to activate any one mine on a continuous segment of mines to activate all the mines of this segment. For manual activation of one mine, the sapper takes $a$ coins. He can repeat this operation as many times as you want.

Also, a sapper can place a mine under a building if it wasn't there. For such an operation, he takes $b$ coins. He can also repeat this operation as many times as you want.

The sapper can carry out operations in any order.

You want to blow up all the mines in the city to make it safe. Find the minimum number of coins that the sapper will have to pay so that after his actions there are no mines left in the city.


-----Input-----

The first line contains one positive integer $t$ ($1 \le t \le 10^5$) — the number of test cases. Then $t$ test cases follow.

Each test case begins with a line containing two integers $a$ and $b$ ($1 \le a, b \le 1000$) — the cost of activating and placing one mine, respectively.

The next line contains a map of mines in the city — a string consisting of zeros and ones.

The sum of the string lengths for all test cases does not exceed $10^5$.


-----Output-----

For each test case, output one integer — the minimum number of coins that the sapper will have to pay.


-----Example-----
Input
2
1 1
01000010
5 1
01101110

Output
2
6



-----Note-----

In the second test case, if we place a mine under the fourth building and then activate it, then all mines on the field are activated. The cost of such operations is six, $b=1$ coin for placing a mine and $a=5$ coins for activating.

Starter code:

Solutions:
t = int(input())

for case in range(t):
    a, b = list(map(int, input().split()))
    s = input()

    z = 10000
    total = 0
    act = False

    for i in range(len(s)):
        cur = s[i]
        if cur == '0':
            z += 1
            act = False
        else:
            if not act:
                act = True
                total += min(a, b * z)
                z = 0

    print(total)


t=int(input())
for you in range(t):
    l=input().split()
    a=int(l[0])
    b=int(l[1])
    s=input()
    n=len(s)
    l=[]
    start=0
    end=0
    done=0
    for i in range(n):
        if(done):
            if(s[i]=='1'):
                end+=1
            else:
                l.append((start,end))
                done=0
        else:
            if(s[i]=='1'):
                done=1
                start=i
                end=i
    if(done):
        l.append((start,end))
    z=a*len(l)
    lo=[]
    for i in range(len(l)-1):
        lo.append(l[i+1][0]-l[i][1]-1)
    for i in lo:
        if(i*b<a):
            z-=a
            z+=(i*b)
    print(z)


for i in range(int(input())):
    a,b=list(map(int,input().split()))
    s=input()
    j=0
    n=len(s)
    l=[]
    while j<n:
        if s[j]=='1':
            x=j
            while s[j]=='1':
                j+=1
                if j==n:
                    break
            y=j-1
            l.append([x,y])
        else:
            j+=1
    ans=0
    j=0
    while j<len(l):
        if j==0:
            ans+=a
        else:
            ans+=min(a,b*(l[j][0]-l[j-1][1]-1))
        j+=1
    print(ans)
                
    
                
            
    


for _ in range(int(input())):
	a,b = list(map(int, input().split()))
	s = input()
	cost = 0
	rowcost = a
	amchain = False
	for c in s:
		if c == '1':
			if not amchain and rowcost:
				amchain = True
				cost += min(rowcost, a)
		else:
			if amchain:
				amchain = False
				rowcost = b
			else:
				rowcost += b
	print(cost)
	


for t in range(int(input())):
    a,b = list(map(int, input().split()))
    m = input()
    x=[]
    i=0
    while i<len(m) and m[i]=='0':
        i+=1
    cs=0

    while i< len(m):
        if m[i]=='0':
            cs+=1
        if m[i]=='1' and cs!=0:
            x+=[cs]
            cs=0
        i+=1
    cp = (len(x)+1)*a
    for i in x:
        if i*b<a:
            cp-=a
            cp+=i*b
    if m=='0'*len(m):
        print(0)
    else:
        print(cp)




for _ in range(int(input())):
    
    a, b = map(int, input().split())
    
    x = 0
    y = 10 ** 10
    
    for i in input():
        
        if i == '0':
            
            x, y = min(x, y), min(y + b, x + b + a)
            
        else:
            
            x, y = 10 ** 10, min(y, x + a)
            
            
    print(min(x, y))

import sys
import math
def II():
	return int(sys.stdin.readline())
 
def LI():
	return list(map(int, sys.stdin.readline().split()))
 
def MI():
	return list(map(int, sys.stdin.readline().split()))
 
def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	a,b = MI()
	s = list(SI())
	x = []
	y = []
	count = 1
	for i in range(1,len(s)):
		if s[i] == s[i-1]:
			count+=1
		else:
			if s[i-1] == "0":
				y.append(0)
			else:
				y.append(1)
			x.append(count)
			count = 1
	if len(s)!=0 and s[-1] == "1":
		y.append(1)
		x.append(count)
	if len(y)!=0 and y[0] == 0:
		y.pop(0)
		x.pop(0)
	y1 = []
	ans = 0
	for i in range(len(y)):
		if y[i] == 0:
			y1.append(x[i])
		else:
			ans+=a
	for i in y1:
		if i*b<a:
			ans-=a
			ans+=i*b
	print(ans)


import sys
for _ in range(int(sys.stdin.readline())):
	a=list(map(int,sys.stdin.readline().strip().split(" ")))
	b=sys.stdin.readline().strip()
	n=0
	inq=False
	s=0
	if b.count("1")!=0:
		for i in b[b.index("1"):]:
			if i=="1":
				if not inq:
					inq=True
					if n!=0:

						s+=min(a[0],n*a[1])
					else:
						s+=a[0]
					n=0
			else:
				inq=False
				n+=1
	print(s)


import sys
input=sys.stdin.readline

t=int(input())
for _ in range(t):
    x,y=list(map(int,input().split()))
    s=list(input())
    if "1" not in s:
        print(0)
    else:
        c=s.index("1")
        d=len(s)-s[::-1].index("1")
        s=s[c:d]
        b=[]
        c=0
        for i in range(len(s)):
            if s[i]=="0":
                c+=1
            else:
                if c!=0:
                    b.append(c)
                c=0
        s=x
        for i in range(len(b)):
            if b[i]*y>x:
                s+=x
            else:
                s+=b[i]*y
        print(s)

import math
import sys


def chek(m, b, c, li):
    for i in range(li):
        if m[i] + b[i] > c:
            return False
    return True


# 113759
input = lambda: sys.stdin.readline().rstrip()
f = int(input())
for _ in range(f):
    a, b = list(map(int, input().split()))
    s = input()
    mas = []
    c = 1
    k = len(s)
    cur = 1
    while c != k:
        if s[c] == s[c - 1]:
            cur += 1
        else:
            if len(mas) != 0:
                mas.append(cur)
                cur = 1
            else:
                if s[c] == "0":
                    mas.append(cur)
                    cur = 1
                else:
                    cur = 1
        c += 1
    if s[c - 1] == "1":
        mas.append(cur)
    ans = 0
    for i in range(len(mas)):
        if i % 2 == 0:
            ans += a
        else:
            if a > b * mas[i]:
                ans += b * mas[i]
                ans -= a
    print(ans)


def f():
    a, b = map(int, input().split())
    s = input()
    ToF = False
    c = 0
    ans = 0
    for item in s:
        if ToF:
            if item == "0":
                c += 1
            else:
                ans += min(c * b, a)
                c = 0
        if item == "1":
            ToF = True
    print(ans + a * ToF)


t = int(input())
for i in range(t):
    f()

t=int(input())
for _ in range(t):
    a,b=list(map(int,input().split()))
    m=input()
    flag=False
    l=[]
    prev=0
    flag=False
    for i in range(len(m)):
        if flag:
            if m[i]=='0':
                l.append((prev,i-1))
                flag=False
            else:
                continue 
        else:
            if m[i]=='0':
                continue
            else:
                flag=True 
                prev=i 
    if flag:
        l.append((prev,len(m)-1))
    # print(l)
    if(len(l)==1):
        print(a)
    elif (len(l)==0):
        print(0)
    else:
        ans=a
        for i in range(1,len(l)):
            if (l[i][0]-l[i-1][1]-1)*b<=a:
                ans+=(l[i][0]-l[i-1][1]-1)*b
            else:
                ans+=a 
        print(ans)
        
        
        


T = int(input())
for t in range(T):
    a, b = [int(x) for x in input().split()]
    mines = input()
    price = 0
    last = ""
    not_mines = []
    there_was_mines = False
    not_mine = 0
    for c in mines:
        if c == '1':
            if last != c:
                price += a
                if not_mine > 0:
                    if there_was_mines:
                        not_mines.append(not_mine)
                    not_mine = 0
            there_was_mines = True
        else:
            not_mine += 1
        last = c
    # print(not_mines)
    for m in not_mines:
        if m*b < a:
            price = price - a + m*b
        
                
                

    print(price)

gans = []
for _ in range(int(input())):
    a, b = map(int, input().split())
    w = list(map(int, list(input())))
    u = []
    k = 1
    for i in range(1, len(w)):
        if w[i] == w[i - 1]:
            k += 1
        else:
            u.append([w[i - 1], k])
            k = 1
    u.append([w[-1], k])
    dp = [0] * len(u)
    if u[0][0] == 1:
        dp[0] = a
    for i in range(1, len(u)):
        if u[i][0] == 0:
            dp[i] = dp[i - 1]
        else:
            if i == 1:
                dp[i] = dp[i - 1] + a
            else:
                dp[i] = min(dp[i - 1] + a, dp[i - 1] + b * u[i - 1][1])
    gans.append(dp[-1])
print(*gans, sep='\n')
            


mod = 10**9 + 7
def solve():
    a, b = map(int, input().split())
    s = input()
    v = []
    tmp = 0
    ok = False
    for i in range(len(s)):
        if s[i] == '1':
            if tmp > 0:
                v.append(tmp)
            tmp = 0
            ok = True
        elif ok:
            tmp += 1
    v.sort()
    ans = a * (len(v) + 1)
    if not ok:
        ans = 0
    for i in range(len(v)):
        if ans >= ans - a + b * v[i]:
            ans = ans - a + b * v[i]
        else:
            break
    print(ans)
t = 1
t = int(input())
while t > 0:
    solve()
    t -= 1

t = int(input())
for _ in range(t):
	a, b = list(map(int, input().split()))
	s = input()
	n = len(s)

	ind1 = 0
	ind2 = n-1

	while ind1 != n and s[ind1] == '0':
		ind1 += 1

	while ind2 != -1 and s[ind2] == '0':
		ind2 -= 1

	if ind1 == n:
		print(0)
		continue

	# print(ind1, ind2)


	arr = []
	count = 0
	for i in range(ind1, ind2+1):
		if s[i] == '0':
			count += 1
		else:
			if count != 0:
				arr += [count]
			count = 0

	if count != 0:
		arr += [count]

	ans = a*(len(arr)+1)

	# print(arr)
	arr.sort()

	tot = 0
	for i in range(len(arr)):
		tot += arr[i]
		ans = min(ans, b*tot + a*(len(arr)-i))

	print(ans)


import sys,math
# import re
# from heapq import *
# from collections import defaultdict as dd
# from collections import Counter as cc
# sys.setrecursionlimit(10**6)#thsis is must
mod = 10**9+7; md = 998244353
input = lambda: sys.stdin.readline().strip()
inp = lambda: list(map(int,input().split()))
#______________________________________________________
for _ in range(int(input())):
	a,b = inp()
	s = str(input())
	ans = []
	c = 0
	for i in s:
		if i=="1":
			c+=1
		else:
			if c==0:
				continue
			ans.append(c)
			c=0
	if c>0:ans.append(c)
	flag = False
	c =0
	res = []
	for i in s:
		if i=="1":
			flag = True
		if flag==True:
			if i=="0":
				c+=1
			else:
				if c==0:
					continue
				res.append(c)
				c = 0
	# print(res)
	# print(ans)
	fin = 0
	if len(ans)>0:
		fin+=a
	if len(ans)>1:
		for i in range(len(res)):
			if res[i]*b>a:
				fin+=a
			else:
				fin+=res[i]*b
	print(fin)



for _ in range (int(input())):
    a,b=map(int,input().split())
    s=input()
    n=len(s)
    j=0
    while j<n and s[j]=='0':
        j+=1
    c=0
    r=a
    if j==n:
        r=0
    damp=0
    for i in range(j,n):
        if s[i]=='1':
            if damp>0:
                r+=min(a,damp*b)
            damp=0
        else:
            damp+=1
        #print(damp,r)
    print(r)

def read_generator():
    while True:
        tokens = input().split(' ')
        for t in tokens:
            yield t

reader = read_generator()

def readword():
    return next(reader)

def readint():
    return int(next(reader))

def readfloat():
    return float(next(reader))

def readline():
    return input()

def solve(a, b, m):
    o = []
    new = True
    i = 0
    for c in m:
        if c == '1':
            if new:
                o.append([i, i])
                new = False
            else:
                o[len(o) - 1][1] = i
        else:
            new = True
        i += 1

    res = len(o) * a

    for i in range(1, len(o)):
        cur = o[i]
        prev = o[i - 1]
        if (cur[0] - prev[1] - 1) * b < a:
            res -= a
            res += (cur[0] - prev[1] - 1) * b

    return res


tests = readint()

for t in range(tests):
    (a, b) = readint(), readint()
    m = readline()
    print(solve(a, b, m))

"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""



T=int(input())
for _ in range(0,T):
    a,b=list(map(int,input().split()))
    s=input()
    ptr1=len(s)
    ptr2=0
    for i in range(0,len(s)):
        if(s[i]=='1' and ptr1==len(s)):
            ptr1=i
        if(s[i]=='1'):
            ptr2=i+1

    if(ptr1==len(s)):
        print(0)
    else:
        L1=[]
        L0=[]
        c=1
        for i in range(ptr1+1,ptr2):
            if(s[i]==s[i-1]):
                c+=1
            else:
                if(s[i-1]=='0'):
                    L0.append(c)
                    c=1
                else:
                    L1.append(c)
                    c=1
        L1.append(c)

        if(len(L1)==1):
            print(a)
        else:
            ans=a
            for i in range(0,len(L1)-1):
                if((b*L0[i])<=a):
                    ans+=(b*L0[i])
                else:
                    ans+=a
            print(ans)
                


t = int(input())
for case in range(t):
    a, b = [int(x) for x in input().split(' ')]
    s = input()
    n = len(s)
    for j in range(2):
        for i in range(len(s)):
            if s[i] != '0':
                break
        s = s[i:]
        s = s[::-1]
    if s == '0':
        s = ''
    y = [u for u in s.split('0') if u]
    c = len(y) * a
    x = [u for u in s.split('1') if u]
    for z in x:
        if len(z) * b < a:
            c -= a
            c += len(z) * b
    print(c)



for _ in range(int(input())):
    a,b = list(map(int,input().split()))
    arr = list(map(int,list(input())))+[0]
    n = len(arr)
    now = 0
    lastEnds = 0
    fl = False
    lenghts = []
    dists = []
    for i in range(n):
        if fl and not arr[i]:
            if len(lenghts):
                dists.append(i-lastEnds-now)
            lenghts.append(now)
            fl = False
            now = 0
            lastEnds = i
        elif fl and arr[i]:
            now+=1
        elif not fl and arr[i]:
            fl = True
            now = 1

    price = a
    if len(lenghts) == 0:
        price = 0

    for i in range(len(dists)):
        if dists[i]*b<a:
            price+=dists[i]*b
        else:
            price+=a

    print(price)