n=int(input())
A=list(map(int,input().split()))
A_=sum(A)
q=int(input())
visit=[0]*10**5
for _ in range(q):
  b,c=map(int,input().split())
  u=A.count(b)
  visit[c-1]+=u
  A_=A_+(u+visit[b-1])*(c-b)
  visit[b-1]=0
  print(A_)