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

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
	b, c = map(int, input().split())
	while b in a:
		a[a.index(b)] = c

	print(sums(a))

