from collections import Counter

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

b = []
c = []
for i in range(q):
	B, C = map(int, input().split())
	b.append(B)
	c.append(C)

arr = Counter(a)

s = sum(arr)

for i in range(q):
	s -= b[i]*arr[b[i]]
	s += c[i]*arr[c[i]]
	arr[c[i]] += arr[b[i]]
	arr[b[i]] = 0
	print(s)