n=int(input())
c=list(map(int,input().split()))
q=int(input())
s=0
for j in range(q):
	r,s=map(int,input().split())
	d=[]
	for i in range(len(c)):
		if(c[i]==r):
			d.append(i)
	for i in d:
		c[i]=s
	print(sum(c))