def sums(l):
	s = 0
	for v in l:
		s += v
	return s

n = int(input())
a = list(map(int, input().split()))
ind = [ [] for x in range(10**6)]

for i in range(n):
	ind[a[i]].append(i)

q = int(input())

for _ in range(q):
	b, c = map(int, input().split())
	if len(ind[b]) == 0:
		print(sums(a))
		continue
	for i in ind[b]:
		a[i] = c
		ind[c].append(i)

	print(sums(a))
