import numpy as np

N=int(input())
A=np.array(list(map(int, input().split())))
ans=[]
Q=int(input())

for i in range(Q):
	B,C=map(int, input().split())
	A=np.where(A==B, C,A)
	ans.append(sum(A))

for i in ans:
	print(i)