N=int(input())
A = list(input().split())
Q = int(input())
pairs = [list(input().split()) for i in range(Q)]

for i in range(Q):
  cnt = 0
  for j in range(N):
    if A[j] == pairs[i][0]:
      A[j] = pairs[i][1]
    cnt += int(A[j])

#  ret = sum(list(map(int,A)))
  print(cnt)
