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())
s = 0
for v in a:
	s += v

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

	s += (ab*c)-(ab*b)
	for i in range(ab):
		ind[c].append(i)

	print(s)
