import numpy as np
from numpy import copy
N=int(input())
numpy_a = np.array(list(map(int, input().split())))
Q=int(input())
newArray = copy(numpy_a)
ans=np.array([None]*Q)
for i in np.arange(Q):
  B,C=map(int, input().split())
  newArray[newArray==B] = C
  ans[i] = (np.sum(newArray))
print('\n'.join(map(str, ans)))
