def tot(x):
	tot= 0
	for d in x:
		tot+= d
	return tot

n = int(input())
start= list(map(int, input().split()))
q= int(input())
for _ in range(q):
	b,c= map(int, input().split())
	for index in range(len(start)):
		if start[index]==b:
			start[index]=c
	print(tot(start))