This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.

You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).

Select two indices $l$ and $r$ ($l < r$).

Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.

If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.

You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 600$) — the number of test cases.

Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) — the length of the strings, and the costs per operation.

The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.

The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.


-----Output-----

For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.


-----Examples-----

Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0


-----Note-----

In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.

In the second test case, we cannot make $a$ equal to $b$ using any number of operations.

In the third test case, we can perform the following operations:

Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.

Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.

The total cost is $6$.

In the fourth test case, we don't have to perform any operations.

Source: codeforces | Difficulty: MEDIUM
Tags: Greedy algorithms

Mathematics

Constructive algorithms


Solutions:
def solve():
	(n, x, y) = [int(i) for i in input().split()]
	(a, b) = (input(), input())
	q = 0
	w = []
	for i in range(n):
		if a[i] != b[i]:
			q += 1
			w.append(i)
	if q % 2 != 0:
		return -1
	if q == 0:
		return 0
	if q != 2 or w[0] + 1 != w[1]:
		return q // 2 * y
	return min(y * 2, x)
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	s1 = input()
	s2 = input()
	temp = []
	for i in range(len(s1)):
		if s1[i] != s2[i]:
			temp.append(i)
	if len(temp) % 2 == 1:
		print(-1)
	elif len(temp) == 2:
		if temp[0] + 1 == temp[1]:
			print(min(x, 2 * y))
		else:
			print(y)
	else:
		print(y * len(temp) // 2)


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	a = list(input())
	b = list(input())
	mis = set()
	for i in range(n):
		a[i] = int(a[i])
		b[i] = int(b[i])
		if a[i] != b[i]:
			mis.add(i)
	if x >= y * 2:
		better_y = True
	else:
		better_y = False
	if len(mis) % 2 == 1:
		print(-1)
	else:
		ans = 0
		if better_y:
			if len(mis) == 2:
				left = mis.pop()
				right = mis.pop()
				if abs(left - right) == 1:
					ans = 2 * y
				else:
					ans = y
			else:
				ans += y * len(mis) // 2
		elif len(mis) == 2:
			left = mis.pop()
			right = mis.pop()
			if abs(left - right) == 1:
				ans = x
			else:
				ans = y
		else:
			ans += y * len(mis) // 2
		print(ans)


t = int(input())
for test in range(t):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input()))
	b = list(map(int, input()))
	if a[0] != b[0]:
		if a[1] != b[1]:
			cnt = 2
			ld = 1
		else:
			cnt = 1
			ld = 0
	elif a[1] != b[1]:
		cnt = 1
		ld = 0
	else:
		cnt = 0
		ld = 0
	for i in range(2, n):
		if a[i] != b[i]:
			cnt += 1
			if a[i - 1] != b[i - 1] and a[i - 2] == b[i - 2]:
				ld += 1
	if cnt % 2 == 1:
		print(-1)
		continue
	if ld == 1 and cnt == 2:
		if y * 2 > x:
			print(x)
		else:
			print(y * 2)
	else:
		print(y * (cnt // 2))


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	A = list(input())
	B = list(input())
	d = 0
	for i in range(n):
		if A[i] != B[i]:
			d += 1
	if d == 0:
		print(0)
		continue
	if d % 2 != 0:
		print(-1)
	else:
		if d == n == 2:
			print(x)
		if d == 2:
			c = 0
			for i in range(n - 1):
				if A[i] != B[i] and A[i + 1] != B[i + 1]:
					c = 1
					break
			if c and n == 3:
				print(x)
			elif c and n > 3:
				if x >= 2 * y:
					print(2 * y)
				else:
					print(x)
			else:
				print(y)
		else:
			print(d * y // 2)


t = int(input())
while t > 0:
	ip = [int(x) for x in input().split()]
	n = ip[0]
	x = ip[1]
	y = ip[2]
	s1 = input()
	s2 = input()
	count = 0
	for i in range(n):
		if s1[i] != s2[i]:
			count += 1
	if count % 2 == 1:
		print(-1)
	elif count == 0:
		print(0)
	elif count <= 2 and n == 2:
		print(x)
	elif count <= 2:
		for i in range(n):
			if s1[i] != s2[i]:
				if s1[i + 1] != s2[i + 1]:
					print(min(x, 2 * y))
				else:
					print(y)
				break
	else:
		print(y * (count // 2))
	t -= 1


def cal():
	if len(p) == 0:
		return 0
	if len(p) == 2:
		if p[1] == p[0] + 1:
			return min(x, 2 * y)
		else:
			return min(y, x * (p[1] - p[0]))
	return len(p) // 2 * y
for jj in range(int(input())):
	(n, x, y) = [int(i) for i in input().split()]
	a = input()
	b = input()
	p = []
	for i in range(n):
		if a[i] != b[i]:
			p.append(i)
	if len(p) % 2 == 1:
		print(-1)
	else:
		print(cal())


def func():
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	diff = []
	for i in range(n):
		if a[i] != b[i]:
			diff.append(i)
	if x > 2 * y:
		x = 2 * y
	if len(diff) % 2 == 1:
		print(-1)
		return
	elif len(diff) == 0:
		print(0)
		return
	elif len(diff) == 2:
		if diff[0] + 1 == diff[1]:
			print(x)
		else:
			print(y)
		return
	else:
		print(len(diff) // 2 * y)
		return
n_tests = int(input())
for i in range(n_tests):
	func()


def f():
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	C = 0
	CG = 0
	for i in range(n - 1):
		if a[i] != b[i] and a[i + 1] != b[i + 1]:
			C += 1
			i += 1
	for i in range(n):
		if a[i] != b[i]:
			CG += 1
	if CG % 2:
		print(-1)
		return
	if C == 1 and CG == 2:
		if n == 2:
			print(x)
		elif 2 * y < x:
			print(2 * y)
		else:
			print(x)
	else:
		temp = CG // 2
		print(temp * y)
t = int(input())
while t:
	f()
	t -= 1


import heapq
import operator

def solve():
	(n, x, y) = map(int, input().strip().split())
	s = input().strip()
	a = [int(ch) for ch in s]
	s = input().strip()
	b = [int(ch) for ch in s]
	n = len(a)
	c = [a[i] ^ b[i] for i in range(n)]
	cnt1 = 0
	pair = 0
	pre = -10
	for i in range(n):
		if c[i] == 1:
			cnt1 += 1
			if pre + 1 == i:
				pair += 1
				pre = -10
			else:
				pre = i
	if cnt1 % 2 == 1:
		print(-1)
		return
	not_pair = cnt1 // 2 - pair
	if y < x and (cnt1 > 2 or pair > 1):
		print(cnt1 // 2 * y)
	elif x <= y * 2:
		print(x * pair + y * not_pair)
	else:
		cost = cnt1 // 2
		if pair > 0:
			cost = max(cost, 2)
		print(cost * y)
t = int(input().strip())
for _ in range(t):
	solve()


tasks = int(input())
for t in range(tasks):
	(n, x, y) = list(map(int, input().split()))
	a = input()
	b = input()
	diff = [i for i in range(n) if a[i] != b[i]]
	if len(diff) % 2 != 0:
		print(-1)
	elif len(diff) != 2:
		print(y * len(diff) // 2)
	elif diff[0] + 1 != diff[1]:
		print(y)
	elif x <= 2 * y:
		print(x)
	elif n <= 3 or (n == 4 and diff[0] == 1 and (diff[1] == 2)):
		print(x)
	else:
		print(2 * y)


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	poss = 0
	for j in range(n):
		if a[j] != b[j]:
			poss += 1
	if poss % 2 != 0:
		print(-1)
		continue
	if poss == 0:
		print(0)
	elif poss > 2:
		print(y * (poss // 2))
	elif poss == 2:
		cons = False
		for j in range(1, n):
			if a[j] != b[j] and a[j - 1] != b[j - 1]:
				cons = True
				break
		if cons:
			print(min(x, 2 * y))
		else:
			print(y)


def solve():
	(n, x, y) = [int(x) for x in input().split()]
	a = input()
	b = input()
	ind = []
	for i in range(n):
		if a[i] != b[i]:
			ind.append(i)
	if len(ind) % 2:
		return -1
	if len(ind) == 2:
		if ind[0] + 1 == ind[1]:
			if n == 2 or n == 3:
				return x
			elif n == 4:
				if ind[0] == 1:
					return x
				else:
					return min(2 * y, x)
			else:
				return min(2 * y, x)
	return y * len(ind) // 2
t = int(input())
while t:
	print(solve())
	t -= 1


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	(x, y) = (max(x, y), min(x, y))
	a = input()
	b = input()
	s = []
	ans = 0
	for i in range(n):
		if a[i] != b[i]:
			ans += 1
			s.append(i)
	if ans & 1 == 1:
		print(-1)
	elif ans == 2 and s[1] - s[0] == 1:
		print(min(x, y * 2))
	else:
		print(ans // 2 * y)


testcases = int(input())
for i in range(testcases):
	input_1 = input().split()
	[n, x, y] = list(map(int, input_1))
	input_2 = input()
	a_list = list(map(int, [*input_2]))
	input_3 = input()
	b_list = list(map(int, [*input_3]))
	n_diff = 0
	cons = False
	diff_last = 0
	for j in range(n):
		diff = abs(a_list[j] - b_list[j])
		if diff == 1:
			n_diff += 1
			if diff_last == 1:
				cons = True
			diff_last = 1
		else:
			diff_last = 0
	if n_diff % 2 == 1:
		print(-1)
	elif n_diff == 2 and cons == True:
		print(min(x, 2 * y))
	else:
		print(n_diff // 2 * y)


testcases = int(input())
while testcases > 0:
	(n, x, y) = [int(x) for x in input().split()]
	array = []
	string1 = input()
	string2 = input()
	for i in range(len(string1)):
		if string1[i] != string2[i]:
			array.append(i)
	if len(array) % 2 != 0:
		print('-1')
	else:
		count = len(array)
		if count > 2:
			print(int(y * count / 2))
		elif count == 0:
			print('0')
		elif int(array[0]) - int(array[1]) not in [1, -1]:
			print(y)
		elif 2 * y < x and n > 2:
			print(2 * y)
		else:
			print(x)
	testcases -= 1


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	yo = []
	for i in range(n):
		if a[i] != b[i]:
			yo.append(i)
	if len(yo) % 2:
		print(-1)
	elif len(yo) == 2:
		if yo[1] == yo[0] + 1:
			print(min(x, 2 * y))
		else:
			print(y)
	else:
		print(len(yo) // 2 * y)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = input().strip()
	b = input().strip()
	ao = a.count('1')
	bo = b.count('1')
	if bo & 1 != ao & 1:
		print(-1)
		continue
	c = []
	for i in range(n):
		if a[i] != b[i]:
			c.append(i)
	s = 0
	if len(c) == 2 and c[0] + 1 == c[1]:
		if x > y * 2:
			s = y * 2
		else:
			s = x
	else:
		s = y * (len(c) // 2)
	print(s)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	p = 0
	q = 0
	for i in range(n):
		if a[i] == '1' and b[i] == '0':
			p += 1
		elif a[i] == '0' and b[i] == '1':
			q += 1
	if (p + q) % 2:
		print(-1)
	else:
		if p + q == 2:
			ans = 0
			count = 0
			flag = 0
			for i in range(n - 1):
				if a[i] != b[i] and a[i + 1] != b[i + 1]:
					if x > 2 * y:
						ans = 2 * y
					else:
						ans = x
					flag = 1
					break
			if flag == 0:
				ans = y
		else:
			ans = (p + q) // 2 * y
		print(ans)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = str(input())
	b = str(input())
	l = []
	for i in range(n):
		if a[i] != b[i]:
			l.append(i)
	if len(l) % 2 == 1:
		print(-1)
	elif len(l) == 2:
		if l[0] + 1 == l[1]:
			if n == 2 or n == 3:
				print(x)
			else:
				print(min(2 * y, x))
		else:
			print(y)
	else:
		print(len(l) // 2 * y)


def main():
	for _ in range(int(input())):
		(n, x, y) = map(int, input().split())
		(a, b) = (input(), input())
		ls = []
		for i in range(n):
			if a[i] != b[i]:
				ls.append(i)
		if len(ls) % 2 == 1:
			print(-1)
			continue
		if len(ls) == 2:
			if ls[1] - ls[0] > 1:
				print(y)
			else:
				print(min(x, y * 2))
		else:
			print(y * (len(ls) // 2))
main()


t = int(input())
for i in range(t):
	l0 = input().split()
	(n, x, y) = (int(l0[0]), int(l0[1]), int(l0[2]))
	a = input()
	b = input()
	con = 0
	l = []
	for j in range(n):
		if a[j] != b[j]:
			l.append(j)
			con += 1
	if con == 0:
		print(0)
	elif con % 2 == 1:
		print(-1)
	else:
		if con == 2:
			if l[1] - l[0] == 1:
				cost = min(2 * y, x)
			else:
				cost = y
		else:
			cost = con // 2 * y
		print(cost)


import io, os, sys
from collections import Counter
t = int(input())
kl12 = 0

def GO_LIFE():
	global kl12
	(n, x, y) = map(int, input().split())
	s = input()
	s1 = input()
	kl = 0
	p = []
	ok1 = 0
	ok2 = 0
	for i in range(n):
		if s[i] != s1[i]:
			p += [i]
			if ok1 == 0 and len(p) == 2:
				if p[0] == p[1] - 1:
					ok2 = 1
					ok1 = 1
			kl += 1
	if kl % 2 == 1:
		print(-1)
		return
	if x > y * 2:
		if len(p) == 2 and ok2 == 1:
			print(y * 2)
		else:
			print(kl // 2 * y)
	else:
		if x == y:
			print(x * (kl // 2))
			return
		sm = 0
		for i in range(0, len(p) - 1, 2):
			if kl > 2 or (kl == 2 and ok2 != 1):
				sm += y
			else:
				sm += x
		print(sm)
while t > 0:
	GO_LIFE()
	t -= 1


import sys
input = sys.stdin.readline

def solve():
	(n, x, y) = map(int, input().split())
	A = input().strip()
	B = input().strip()
	diff = []
	for i in range(n):
		if A[i] != B[i]:
			diff.append(i)
	m = len(diff)
	if m % 2:
		return -1
	elif m == 2:
		return y if diff[0] + 1 < diff[1] else min(2 * y, x)
	else:
		return y * (m // 2)
for _ in range(int(input())):
	print(solve())


for i in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	ch1 = a.count('1')
	ch2 = b.count('1')
	if abs(ch1 - ch2) % 2 == 0:
		j = 0
		sum = 0
		while j < n:
			if a[j] != b[j]:
				sum += 1
			j += 1
		if sum > 2:
			print(int(sum // 2 * y))
		elif sum == 2:
			values = []
			p = 0
			while p < n:
				if a[p] != b[p]:
					values.append(p)
				p += 1
			if values[1] - values[0] == 1:
				print(min(2 * y, x))
			else:
				print(y)
		else:
			print(0)
	else:
		print(-1)


R = lambda : map(int, input().split())
(t,) = R()
for k in range(t):
	(n, x, y) = R()
	a = input()
	b = input()
	indices = []
	for i in range(len(a)):
		if a[i] != b[i]:
			indices.append(i)
	length = len(indices)
	if length == 0:
		print(0)
	elif length % 2 != 0:
		print(-1)
	elif length == 2:
		if indices[0] == indices[1] + -1:
			if x > 2 * y and (indices[1] + 3 <= n or indices[0] >= 2):
				print(2 * y)
			else:
				print(x)
		else:
			print(y)
	else:
		print(length // 2 * y)


def solve():
	[n, x, y] = [int(x) for x in input().split()]
	a = input()
	b = input()
	arr = []
	count = 0
	count_idx = []
	for idx in range(n):
		if a[idx] == b[idx]:
			arr.append(0)
		else:
			arr.append(1)
			count += 1
			count_idx.append(idx)
	if count == 0:
		print(0)
		return
	if count % 2 == 1:
		print(-1)
		return
	if count == 2:
		if count_idx[0] == count_idx[-1] - 1:
			print(min(x, 2 * y))
			return
		print(y)
		return
	p = 0
	if y <= x:
		print(count // 2 * y)
		return
	id = 1
	while id < n:
		if arr[id - 1] == 1 and arr[id] == 1:
			p += 1
			id += 2
			continue
		id += 1
	print((count // 2 - p) * y + p * x)
for _ in range(int(input())):
	solve()


for i in range(int(input())):
	(n, x, y) = input().split(' ')
	(n, x, y) = (int(n), int(x), int(y))
	a = input()
	b = input()
	arr = []
	p = 0
	for i in range(n):
		if a[i] != b[i]:
			arr.append(i)
			p += 1
	if p % 2:
		print(-1)
		continue
	if p == 2 and n >= 5 and (arr[0] == arr[1] - 1):
		print(min(x, 2 * y))
	elif p == 2 and n == 2 or (n == 3 and arr[0] == arr[1] - 1):
		print(x)
	elif p == 2 and arr[0] == arr[1] - 1:
		if arr == [1, 2]:
			print(x)
		else:
			print(min(x, 2 * y))
	else:
		print(y * p // 2)


for _ in range(int(input())):
	(n, x, way) = map(int, input().split())
	a = input()
	b = input()
	l = []
	for i in range(n):
		if a[i] != b[i]:
			l.append(i)
	if len(l) % 2 == 0:
		z = len(l)
		if z == 0:
			print(0)
		elif z == 2:
			if abs(l[1] - l[0]) == 1:
				print(min(x, 2 * way))
			else:
				print(way)
		else:
			print(z // 2 * way)
	else:
		print(-1)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	l1 = [int(z) for z in list(input())]
	l2 = [int(z) for z in list(input())]
	changes = 0
	changes_ind = []
	out = 0
	for v in range(n):
		if l1[v] != l2[v]:
			changes += 1
			changes_ind.append(v)
	if changes % 2:
		print(-1)
		continue
	if not changes:
		print(0)
		continue
	changes_ind_len = len(changes_ind)
	if changes_ind_len == 2 and abs(changes_ind[0] - changes_ind[1]) == 1:
		out = min(x, 2 * y)
	else:
		out = changes_ind_len // 2 * y
	print(out)


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split(' '))
	a = [int(i) for i in input()]
	b = [int(i) for i in input()]
	sum = 0
	flag = 0
	found = 0
	for i in range(n):
		if a[i] - b[i] != 0:
			sum += 1
			if flag == 1:
				found = 1
			else:
				flag = 1
		else:
			flag = 0
	if sum % 2 == 1:
		print('-1')
		continue
	if sum == 2 and found == 1:
		if x > 2 * y:
			print(2 * y)
		else:
			print(x)
	elif sum == 2 and found == 0:
		print(y)
	else:
		print(int(sum / 2 * y))


t = eval(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	ind = []
	for i in range(n):
		if a[i] != b[i]:
			ind.append(i)
	if len(ind) % 2 == 1:
		print(-1)
	else:
		l = len(ind)
		if l != 2 or ind[0] + 1 != ind[1]:
			print(y * l // 2)
		else:
			print(min(x, 2 * y))


for mak in range(int(input())):
	(n, x, y) = map(int, input().split())
	Flag = 0
	s = input()
	b = input()
	l = []
	for i in range(n):
		if s[i] != b[i]:
			l.append(i)
	if len(l) % 2 == 0:
		has = len(l)
		if has == 0:
			print(0)
			Flag += 2
		elif has == 2:
			if abs(l[1] - l[0]) == 1:
				print(min(x, 2 * y))
			else:
				Flag += 3
				print(y)
		else:
			print(has // 2 * y)
	else:
		print(-1)


for loop in range(int(input())):
	(name, x, y) = map(int, input().split())
	Flag = 0
	Flag7 = 0
	s = input()
	b = input()
	l = []
	for i in range(name):
		if s[i] != b[i]:
			l.append(i)
			Flag7 += 9
	if len(l) % 2 == 0:
		has = len(l)
		if has == 0:
			print(0)
			Flag += 2
		elif has == 2:
			if abs(l[1] - l[0]) == 1:
				print(min(x, 2 * y))
			else:
				Flag += 3
				print(y)
				Flag7 += 6
		else:
			print(has // 2 * y)
	else:
		print(-1)


t = int(input().strip())

def solve(n, x, y, a, b):
	re = 0
	cab = a.count('1') + b.count('1')
	place = []
	k = 0
	if cab % 2 == 1:
		return -1
	cab = 0
	for i in range(n):
		if a[i] != b[i]:
			if a[i] == '1':
				cab += 1
			if b[i] == '1':
				cab += 1
			k += 1
			if len(place) < 2:
				place.append(i)
	if k == 2:
		if cab == 2 and place[1] - place[0] == 1:
			return min(x, 2 * y)
	return int(k / 2) * y
for _ in range(t):
	(n, x, y) = map(int, input().split(' '))
	a = list(input())
	b = list(input())
	print(solve(n, x, y, a, b))


for _ in range(int(input())):
	(inp_n, i_x, sol) = map(int, input().split())
	a = input()
	b = input()
	l = []
	for i in range(inp_n):
		if a[i] != b[i]:
			l.append(i)
	if len(l) % 2 == 0:
		z = len(l)
		if z == 0:
			print(0)
		elif z == 2:
			if abs(l[1] - l[0]) == 1:
				print(min(i_x, 2 * sol))
			else:
				print(sol)
		else:
			print(z // 2 * sol)
	else:
		print(-1)


def get_numbers_list(string_list):
	string_split_list = string_list.split()
	number_list = []
	for element in string_split_list:
		number_list.append(int(element))
	return number_list

def main():
	t = int(input())
	for i in range(t):
		(n, x, y) = map(int, input().split())
		a = int(input(), 2)
		b = a ^ int(input(), 2)
		c = bin(b).count('1')
		if c % 2:
			print(-1)
		elif c == 2 and b & b << 1:
			print(min(2 * y, x))
		else:
			print(y * c // 2)
main()


for mak in range(int(input())):
	(n, a, b) = map(int, input().split())
	Flag = 0
	s = input()
	p = input()
	m = []
	for i in range(n):
		if s[i] != p[i]:
			m.append(i)
	if len(m) % 2 == 0:
		has = len(m)
		if has == 0:
			print(0)
			Flag += 2
		elif has == 2:
			if abs(m[1] - m[0]) == 1:
				print(min(a, 2 * b))
			else:
				Flag += 3
				print(b)
		else:
			print(has // 2 * b)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	k = list()
	r = 0
	for j in range(n):
		if a[j] != b[j]:
			k.append(j)
	if len(k) % 2 != 0:
		print(-1)
	else:
		for f in range(0, len(k), 2):
			if x < y or len(k) == 2:
				if k[f + 1] - k[f] == 1:
					r += min(y * 2, x)
				else:
					r += y
			else:
				r += y
		print(r)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = int(input(), 2)
	b = a ^ int(input(), 2)
	c = bin(b)[2:].count('1')
	if c % 2:
		print(-1)
	elif c == 2 and b & b << 1:
		print(min(2 * y, x))
	else:
		print(y * c // 2)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	changes = []
	for i in range(n):
		if a[i] != b[i]:
			changes.append(i)
	k = len(changes)
	if k % 2 == 1:
		print(-1)
		continue
	start = 0
	end = k - 1
	if not k:
		print(0)
		continue
	if len(changes) > 2:
		print(len(changes) // 2 * y)
		continue
	if changes[1] - changes[0] == 1:
		if x > 2 * y:
			if n > 4:
				print(2 * y)
			elif n == 4 and changes[0] != 1:
				print(2 * y)
			else:
				print(x)
		else:
			print(x)
	else:
		print(y)


for _ in range(int(input())):
	(n, x, y) = list(map(int, input().split()))
	a = list(input())
	b = list(input())
	n_d = 0
	r = 0
	d = []
	for i in range(n):
		if a[i] != b[i]:
			d.append(i)
			n_d += 1
	if n_d % 2 == 0:
		if n_d == 2 and d[1] - d[0] == 1:
			r += min(x, y * 2)
		else:
			r += y * (len(d) // 2)
		print(r)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	nxy = [int(i) for i in input().split()]
	(n, x, y) = (nxy[0], nxy[1], nxy[2])
	a = [int(i) for i in input()]
	b = [int(i) for i in input()]
	if a == b:
		print(0)
		continue
	(k, c) = (0, 0)
	for i in range(n):
		if a[i] != b[i]:
			k += 1
			c = i
	if k % 2 == 1:
		print(-1)
		continue
	if k != 2:
		print(y * k // 2)
		continue
	if a[c - 1] == b[c - 1]:
		print(y)
		continue
	if x <= 2 * y:
		print(x)
		continue
	if n <= 3:
		print(x)
		continue
	if n == 4 and c == 2:
		print(min(x, 3 * y))
	print(2 * y)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	c = ''
	k = min(x, 2 * y)
	for i in range(n):
		if a[i] == b[i]:
			c += '0'
		else:
			c += '1'
	if c.count('1') % 2:
		print(-1)
	elif c.count('1') == 0:
		print(0)
	else:
		d = c.count('1')
		l = c.index('1')
		c1 = c[::-1]
		r = n - c1.index('1') - 1
		if d == 2:
			if r - l == 1:
				print(min(x, 2 * y))
			else:
				print(min((r - l) * x, y))
		else:
			print(y * d // 2)


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split(' '))
	a = input()
	b = input()
	c = list(map(lambda x: x[0] != x[1], zip(a, b)))
	if sum(c) % 2 == 1:
		print(-1)
	elif sum(c) == 0:
		print(0)
	elif n == 2:
		print(x)
	elif n == 3:
		if c[1]:
			print(x)
		else:
			print(min(2 * x, y))
	elif n == 4:
		if sum(c) == 4:
			print(min(2 * y, 2 * x))
		elif c[1] and c[2]:
			print(min(x, 3 * y))
		else:
			print(min(x, 2 * y))
	elif sum(c) == 2:
		bb = False
		for (j1, j2) in zip(c, c[1:]):
			if j1 and j2:
				bb = True
		if bb:
			print(min(x, 2 * y))
		else:
			print(min(y, x))
	else:
		print(y * (sum(c) // 2))


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	a = input()
	b = input()
	c = [0] * n
	count = 0
	last_occurence = -1
	for i in range(n):
		if a[i] != b[i]:
			c[i] = 1
			count += 1
			last_occurence = i
	if count % 2 != 0:
		print(-1)
	elif count == 2:
		if c[last_occurence - 1] == 1:
			if 2 * y < x and n >= 4:
				print(2 * y)
			else:
				print(x)
		else:
			print(y)
	else:
		print(y * (count // 2))


def miis():
	return map(int, input().split())
for _ in range(int(input())):
	(n, x, y) = miis()
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	sma = sum(a)
	smb = sum(b)
	if (n - sum(a)) % 2 != (n - sum(b)) % 2:
		print(-1)
		continue
	ans = 0
	f = []
	for i in range(n):
		if a[i] != b[i]:
			f.append(i)
	if len(f) == 2 and f[1] - f[0] == 1:
		ans += min(2 * y, x)
	else:
		ans += y * len(f) // 2
	print(ans)


from typing import List, Dict, Set, Sequence, Tuple, Deque, AnyStr, Optional
from collections import deque, Counter, OrderedDict
case_num = int(input())
for case_index in range(case_num):
	(n, x, y) = map(int, input().split(' '))
	s1 = input()
	s2 = input()
	different = 0
	a = -1
	b = -1
	for i in range(n):
		if s1[i] != s2[i]:
			different += 1
			if a == -1:
				a = i
			else:
				b = i
	if different % 2 != 0:
		print(-1)
	elif different == 2 and a == b - 1:
		print(min(x, 2 * y))
	else:
		print(different // 2 * y)