n = int(input())
l = list(map(int, input()))
q = int(input())
count = 0

for i in range(q):
	count = 0
	b, c = map(int, input().split())
	for a in l:
		if a == b:
			l[count] = c
		print(sum(l))
		count++
