------
## 最终结论
```python
def minimum_coins(t, test_cases):
    results = []
    for a, b, mines in test_cases:
        n = len(mines)
        segments = []
        i = 0
        while i < n:
            if mines[i] == '1':
                start = i
                while i < n and mines[i] == '1':
                    i += 1
                segments.append((start, i - 1))
            else:
                i += 1

        if not segments:
            results.append(0)
            continue

        total_cost = a
        for j in range(1, len(segments)):
            gap_length = segments[j][0] - segments[j-1][1] - 1
            total_cost += min(a, gap_length * b)

        results.append(total_cost)

    return results

# Input processing and function calling
import sys
input = sys.stdin.read
data = input().split()

t = int(data[0])
index = 1
test_cases = []

for _ in range(t):
    a = int(data[index])
    b = int(data[index + 1])
    mines = data[index + 2]
    test_cases.append((a, b, mines))
    index += 3

results = minimum_coins(t, test_cases)
for result in results:
    print(result)
```