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())

for i in range(Q):
  L, R = map(int,(input().split()))
  B_count=np.count_nonzero(npArray == L)
  sa=(R-L)*B_count
  npArray = np.where(npArray == L,R, npArray)
  ans= ans+sa
  print(ans)