n = int(input())
l = list(map(int, input().split()))
q = int(input())
count = 0
s = []

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

[print(i) for i in s]
