from collections import Counter, defaultdict

n = int(input())
nums = list(map(int, input().split()))
q = int(input())
queries = [list(map(int, input().split())) for _ in range(q)]

ans = sum(nums)
d = Counter(nums)

for query in queries:
	k = d[query[0]]
	if k >= 1:
		ans += (query[1] - query[0]) * k
		d[query[1]] += k
	print(ans)