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

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

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

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

		else:
			ind[c] = [i]
			
	print(sums(a))
