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):
    x=bc[i][0]
    y=bc[i][1]
    c=a.count(x)
    if x in a:
      ind=[j for j,m in enumerate(a) if m == x]
      sum+=(y-x)*c
      for j in ind:
        a[j]=bc[i][1]
    else:
      pass
    print(sum)