def func(a,b,c):
	for j in range(len(a)):
		if a[j]==b:
			a[j]=c
		else:
			pass

n = int(input())
a = list(map(int,input().split()))
q = int(input())
for k in range(q):
	b,c = map(int,input().split())
	func(a,b,c)
	ans = sum(a)
	print(ans)