n = int(input())
a = list(map(int, input().split()))
q = int(input())

bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]

for i in range(q):
	for j in range(n):
		if a[j] ==b[i]:
			a[j] = c[i]

	print(sum(a))