import numpy

tmp=input()
list=input().split(" ")
array=numpy.zeros(len(list),dtype=">i4")
for i in range(len(list)):
  array[i]=int(list[i])

a=int(input())
sum=numpy.sum(array)

for i in range(a):
  b=input().split(" ")
  if int(b[0]) in array:
    b0=int(b[0])
    b1=int(b[1])
    pos=len(numpy.where(array==b0)[0])
    array=numpy.where(array==b0,b1,array)
    diff=pos*(b1-b0)
    sum+=diff
    print(sum)
  else:
    sum=numpy.sum(array)
    print(sum)
  