import numpy as np
N=int(input())
A=list(map(int,(input().split())))
npArray = np.array(A)
npArray=npArray.copy()
ans=np.sum(npArray)
Q=int(input())
B=[]
C=[]
for _ in range(Q):
  L, R = map(int,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  B_count=np.count_nonzero(npArray == B[i])
  sa=(C[i]-B[i])*B_count
  upNpArray = np.where(npArray == B[i], C[i], npArray)
  ans= ans+sa
  print(ans)
  npArray=upNpArray.copy()
