n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
sum=sum(a)
for i in range(q):
    c=a.count(bc[i][0])
    if bc[i][0] in a:
      ind=[j for j,x in enumerate(a) if x == bc[i][0]]
      sum+=(bc[i][1]-bc[i][0])*c
      for j in ind:
        a[j]=bc[i][1]
    else:
      pass
    print(sum)