# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
hash = [0]*100000
for i in range(Q):
    proc_append(tuple(input().split()))
    process[i] = tuple(map(int,process[i]))

goukei = sum(A)

for i in A:
	hash[i] += 1

for b,c in process:
	if hash[b] != 0:
		goukei += (c-b)*hash[b]
		hash[c] += hash[b]
		hash[b] = 0
	print(goukei)