n= int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int,input().split())) for i in range(q)]
# print(b)
a_replace = a
for i in range(q):
  if b[i][0] in a_replace:
    a_replace = [b[i][1] if j==b[i][0] else j for j in a_replace]
  # print(a_replace)
  print(sum(a_replace))