N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
C=[]
for i in range(Q):
  b,c=map(int,input().split())
  B.append(b)
  C.append(c)

for i in range(Q):
  ans = 0
  for j in range(len(A)):
    if A[j] == B[i]:
      A[j]=C[i]
      ans += A[j]
    else:
      ans += A[j] 
  print(ans)