N=int(input())
A=list(int(x) for x in input().split())
Q=int(input())
X=[list(map(int,input().split())) for i in range(Q)]

for i in range(Q):
	sum=0
	Aaf=[X[i][1] if j==X[i][0] else j for j in A]
	for k in range(N):
		sum+=Aaf[k]
	print(sum)
	A=Aaf