import copy

n = int(input())
a = list(map(str, input().split()))
q = int(input())
vl = []
for i in range(q):
  v = list(map(int, input().split()))
  vl.append(v)
sal = []
for i in range(len(vl)):
  ta = []
  ta = copy.deepcopy(a)
  for j in range(len(ta)):
    if ta[j] == str(vl[i][0]):
      ta[j] = str(vl[i][1])
  sal.append(ta)
  a = copy.deepcopy(ta)
ssal = []
for i in range(len(sal)):
  smsal = 0
  for j in range(len(sal[i])):
    smsal += int(sal[i][j])
  ssal.append(smsal)
for i in ssal:
  print(i)