n=int(input())
a=list(map(int,input().split()))
q=int(input())
ans=0
for i in range(q):
	b,c=map(int,input().split())
	for i,num in enumerate(a):
		if num==b:
			a[i]=c
			ans+=c
		else:
			ans+=num
	print(ans)
	ans=0