n = int(input())
m = list(map(int, input().strip().split(' ')))
s = int(input())

for i in range(s):
	a = list(map(int, input().strip().split(' ')))
	for j in range(len(m)):
		if m[j]==a[0]:
			m[j]=a[1]
	print(sum(m))