n = int(input())
a = [int(x.strip()) for x in input().split()]
bc = []
q = int(input())
for i in range(q):
  bc_i = [int(y.strip()) for y in input().split()]
  bc.append(bc_i)
for j in range(q):
  a = [bc[j][1] if bc[j][0] == i else i for i in a]
  print(sum(a))