N = int(input())
A = list(map(int, input().split()))
Q = int(input())

num = []

for i in range(1, 100000):
	# 行列Aの要素にiが何個あるか数えてnumに追加
	num.append(A.count(i))

S = sum(A)
slist = []

for i in range(Q):
	B, C = map(int, input().split())
	numb = num[B-1]
	S += (C - B) * numb
	num[C-1] += numb
	num[B-1] = 0
	slist.append(S)

[print(i) for i in slist]