n = int(input())
line = list(map(int, input().split()))
q = int(input())
for i in range(0, q):
	b, c = map(int, input().split())
	for j in range(0, len(line)):
		if line[j] == b: line[j] = c
	print(sum(line))