n = int(input())
a = list(map(int, input().split()))
q = int(input())
vl = []
for i in range(q):
  v = list(map(int, input().split()))
  vl.append(v)
toa = sum(a)

sal = []
for i in range(len(vl)):
  ac = a.count(vl[i][0])
  dv = vl[i][1] - vl[i][0]
  toa += dv * ac
  for j in range(len(a)):
    if a[j] == vl[i][0]:
      a[j] = vl[i][1]
  sal.append(toa)

for i in sal:
  print(i)