n = int(input())
li = list(map(int,input().split()))
k = int(input())
for i in range(k):
	a,b = map(int,input().split())
	for nj in li:
		if nj==a:
			inde = li.index(nj)
			li.pop(inde)
			li.insert(inde,b)
	print(sum(li))