Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef is going on a road trip and needs to apply for inter-district and inter-state travel e-passes. It takes A minutes to fill each inter-district e-pass application and B minutes for each inter-state e-pass application.

His journey is given to you as a binary string S of length N where 0 denotes crossing from one district to another district (which needs an inter-district e-pass), and a 1 denotes crossing from one state to another (which needs an inter-state e-pass).

Find the total time Chef has to spend on filling the various forms.

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains two lines of input.
- First line contains three space separated integers N, A and B.
- Second line contains the string S.

------ Output Format ------ 

For each testcase, output in a single line the total time Chef has to spend on filling the various forms for his journey.

------ Constraints ------ 

$1 ≤ T ≤ 10^{2}$
$1 ≤ N, A, B ≤ 10^{2}$
$S_{i} \in \{'0', '1'\}$

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3
2 1 2
00
2 1 1
01
4 2 1
1101
----- Sample Output 1 ------ 
2
2
5
----- explanation 1 ------ 
Test case $1$: Chef needs total $2$ inter-district e-passes, and he will be filling them in total $1 \cdot 2 = 2$ minutes.

Test case $3$: Chef needs total $1$ inter-district e-pass and $3$ inter-state e-passes, and he will be filling them in total $2 \cdot 1 + 1 \cdot 3 = 5$ minutes.

Difficulty: EASY
Tags: Mathematics

Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
test = int(input())
for i in range(test):
	(n, a, b) = map(int, input().split())
	s = input()
	for j in s:
		one = s.count('1')
		zero = s.count('0')
	print(one * b + zero * a)


for i in range(int(input())):
	(N, A, B) = map(int, input().split())
	S = input()
	time = 0
	for i in S:
		if i == '1':
			time += B
		else:
			time += A
	print(time)


for i in range(int(input())):
	(n, a, b) = list(map(int, input().split()))
	s = input()
	d = 0
	t = 0
	for i in s:
		if int(i) & 1:
			t += 1
		else:
			d += 1
	print(d * a + t * b)


from collections import Counter
for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = list(input())
	c = Counter(l)
	c0 = c['0']
	c1 = c['1']
	print(a * c0 + b * c1)


s = int(input())
for i in range(s):
	(n, a, b) = map(int, input().split(' '))
	m = input()
	count1 = 0
	for j in range(n):
		if m[j] == '1':
			count1 += b
		if m[j] == '0':
			count1 += a
	print(count1)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	(count_0, count_1) = (0, 0)
	for i in s:
		if i == '0':
			count_0 += 1
		elif i == '1':
			count_1 += 1
	print(count_0 * a + count_1 * b)


for i in range(int(input())):
	(N, A, B) = map(int, input().split())
	s = input()
	print(s.count('0') * A + s.count('1') * B)


t = int(input())
for i in range(t):
	(n, d, s) = list(map(int, input().split()))
	st = input()
	zero = 0
	one = 0
	for k in st:
		if k == '0':
			zero = zero + 1
		else:
			one = one + 1
	print(s * one + d * zero)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	x = s.count('1')
	y = s.count('0')
	print(y * a + x * b)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	h = s.count('1')
	r = s.count('0')
	print(b * h + a * r)


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	lst = list(s)
	count0 = 0
	count1 = 0
	for i in range(n):
		if lst[i] == '0':
			count0 += 1
		elif lst[i] == '1':
			count1 += 1
	mult = count0 * a + count1 * b
	print(mult)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	dist = s.count('0') * a
	state = s.count('1') * b
	print(dist + state)


t = int(input())
while t > 0:
	(n, a, b) = map(int, input().split())
	s = input()
	one = 0
	for i in range(n):
		if s[i] == '1':
			one += 1
	zero = n - one
	print(a * zero + b * one)
	t -= 1


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = str(input())
	amount = 0
	for i in range(n):
		if '0' in s[i]:
			amount += a
		elif '1' in s[i]:
			amount += b
	print(amount)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = str(input())
	c = 0
	for j in range(n):
		if '0' in s[j]:
			c = c + a
		elif '1' in s[j]:
			c = c + b
	print(c)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = input()
	print(s.count('0') * b + s.count('1') * c)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	(c1, c0) = (0, 0)
	for ch in s:
		if ch == '0':
			c0 += 1
		else:
			c1 += 1
	print(c0 * a + c1 * b)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	s = list(input())
	tm = 0
	for i in s:
		if i == '0':
			tm += a
		else:
			tm += b
	print(tm)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	(c, k) = (0, 0)
	for i in range(n):
		if s[i] == '0':
			c += 1
		else:
			k += 1
	print(c * a + k * b)


for i in range(int(input())):
	x = input().split()
	v = input()
	c = int(x[2])
	cc = int(x[1])
	b = 0
	for i in v:
		if i == '0':
			b = b + cc
		else:
			b = b + c
	print(b)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	ans = 0
	for i in s:
		if i == '0':
			ans += a
		else:
			ans += b
	print(ans)


for i in range(int(input())):
	(N, A, B) = map(int, input().split())
	S = input()
	t = 0
	for j in S:
		if j == '0':
			t = t + A
		else:
			t = t + B
	print(t)


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = list(map(int, input()))
	f = 0
	for j in s:
		if j == 0:
			f += a
		else:
			f += b
	print(f)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	s = input()
	a = s.count('1')
	b = s.count('0')
	print(a * k + m * b)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = list(input())
	s0 = s.count('0')
	s1 = s.count('1')
	print(s0 * a + s1 * b)


from collections import Counter

def get(d, v):
	if d.get(v) == None:
		return 0
	else:
		return d.get(v)
for _ in range(int(input())):
	(n, z, o) = map(int, input().split())
	s = input()
	l = [int(x) for x in s]
	d = dict(Counter(l))
	r = 0
	r = z * get(d, 0) + o * get(d, 1)
	print(r)


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	c = input()
	d = 0
	e = 0
	for i in range(n):
		if c[i] == '0':
			d += 1
		else:
			e += 1
	print(d * a + e * b)


for i in range(int(input())):
	(x, y, z) = map(int, input().split())
	s = input()
	t = 0
	for j in s:
		if j == '0':
			t += y
		else:
			t += z
	print(t)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	lst = list(s)
	zero = lst.count('0')
	one = lst.count('1')
	print(zero * a + one * b)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	z = s.count('0')
	o = s.count('1')
	print(z * a + o * b)


t = int(input())
for tc in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	print(a * s.count('0') + b * s.count('1'))


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	d = s.count('0')
	st = len(s) - d
	print(a * d + b * st)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	A = 0
	B = 0
	for i in s:
		if i == '0':
			A = A + a
		elif i == '1':
			B = B + b
	print(A + B)


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = str(input())
	c1 = s.count('1')
	c0 = s.count('0')
	print(c0 * a + c1 * b)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = input()
	time = 0
	for i in s:
		if i == '0':
			time = time + b
		else:
			time = time + c
	print(time)


for p in range(int(input())):
	(n, a, b) = map(int, input().split())
	travel = input()
	time = 0
	for i in travel:
		if i == '0':
			time += a
		else:
			time += b
	print(time)


from collections import Counter
t = int(input())
for i in range(t):
	(n, a, b) = list(map(int, input().split()))
	lst = input()
	k = Counter(lst)
	print(a * k['0'] + b * k['1'])


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	interdist = s.count('0')
	interst = s.count('1')
	min = interdist * a + interst * b
	print(min)


def main():
	t = int(input())
	for i in range(t):
		(n, a, b) = map(int, input().split())
		s = input().strip()
		inter_district = s.count('0')
		inter_state = s.count('1')
		time = inter_district * a + inter_state * b
		print(time)
main()


for _ in range(int(input())):
	(N, dis, state) = map(int, input().split())
	journey = input()
	print(journey.count('0') * dis + journey.count('1') * state)


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	y = s.count('0')
	u = s.count('1')
	print(y * a + u * b)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	z = 0
	o = 0
	for i in s:
		if i == '0':
			z += 1
		else:
			o += 1
	print(z * a + o * b)


t = int(input())
while t > 0:
	(n, a, b) = map(int, input().split())
	s = list(input())
	k = s.count('0') * a + s.count('1') * b
	print(k)
	t = t - 1


import re
for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	l1 = re.findall('0', s)
	l2 = re.findall('1', s)
	print(len(l1) * a + len(l2) * b)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = str(input())
	x = s.count('0')
	y = s.count('1')
	print(y * b + x * a)


T = int(input())
for _ in range(T):
	(n, a, b) = map(int, input().split())
	s = input()
	print(a * s.count('0') + b * s.count('1'))


def solve():
	ones = s.count('1')
	zeros = s.count('0')
	return ones * b + zeros * a
for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	print(solve())


from collections import Counter
for i in range(int(input())):
	(n, d, s) = map(int, input().split())
	t = input()
	t = list(t)
	c = Counter(t)
	sum_pass = d * c['0'] + s * c['1']
	print(sum_pass)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	s = input()
	one = s.count('1')
	zero = s.count('0')
	c = print(one * b + zero * a)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	string = input()
	print(string.count('0') * a + string.count('1') * b)


t = int(input())
while t:
	t -= 1
	(n, a, b) = map(int, input().split())
	s = list(input())
	x = s.count('0')
	y = s.count('1')
	print(a * x + y * b)


T = int(input())
for i in range(T):
	(N, A, B) = map(int, input().split())
	S = str(input())
	inter_district = 0
	inter_state = 0
	for i in range(1, N + 1):
		a = S[i - 1:i]
		if a == '1':
			inter_state = inter_state + 1
		else:
			inter_district = inter_district + 1
	total_time = A * inter_district + B * inter_state
	print(total_time)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	d = input()
	x = d.count('0')
	y = d.count('1')
	f = x * b + y * c
	print(f)


for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = list(map(int, input()))
	p = 0
	q = 0
	for i in s:
		if i == 0:
			p = p + a
		else:
			p = p + b
	print(p)


for t in range(int(input())):
	(n, a, b) = map(int, input().split(' '))
	s = input()
	num1 = s.count('0')
	num2 = s.count('1')
	print(num1 * a + num2 * b)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split(' '))
	s = input()
	ctr1 = 0
	ctr2 = 0
	for j in s:
		if j == '0':
			ctr1 += 1
		else:
			ctr2 += 1
	total_time = ctr1 * a + ctr2 * b
	print(total_time)


for i in range(int(input())):
	a = [int(x) for x in input().split()]
	(x, y) = (a[1], a[2])
	b = list(input())
	d = 0
	for j in b:
		if j == '0':
			d += x
		else:
			d += y
	print(d)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	s = input()
	sum1 = 0
	sum11 = 0
	for ele in set(s):
		if ele == '0':
			sum1 = sum1 + s.count(ele) * b
		else:
			sum11 = sum11 + s.count(ele) * c
	print(sum1 + sum11)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = input()
	intdst = 0
	intsta = 0
	for i in s:
		if i == '0':
			intdst += 1
		else:
			intsta += 1
	time = intdst * a + intsta * b
	print(time)


t = int(input())
while t > 0:
	(n, a, b) = map(int, input().split(' '))
	s = input()
	z = s.count('1')
	x = s.count('0')
	print(x * a + z * b)
	t -= 1


T = int(input())
for i in range(T):
	(N, A, B) = map(int, input().split())
	S = input()
	x = S.count('0')
	y = S.count('1')
	print(A * x + B * y)


T = int(input())
x = range(T)
for i in x:
	(n, a, b) = map(int, input().split())
	s = input()
	y = s.count('0')
	z = s.count('1')
	print(a * y + b * z)


testcase = int(input())
for t in range(testcase):
	(N, A, B) = (int(item) for item in input().split())
	S = input()
	timeD = 0
	timeS = 0
	for num in S:
		if num == '0':
			timeD += A
		else:
			timeS += B
	totalT = timeS + timeD
	print(totalT)