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):
	if X[i][0] not in A:
		print(sum(A))
	else:
		Aaf=[X[i][1] if j==X[i][0] else j for j in A]
		print(sum(Aaf))
		A=Aaf

