n=int(input())
A=list(map(int,input().split(" ")))
B=[]
S=0
for i in range(1000000):
  B.append(A.count(i))
for i in A:
  S=S+i
q=int(input())
for i in range(q):
  b,c=map(int,input().split(" "))
  S=S+(c-b)*B[b]
  print(S)
  B[c]=B[c]+B[b]
  B[b]=0