N=int(input())
A=list(map(int,input().split()))
X=[0]*(10**5+1)
for i in range(N):
  X[A[i]]+=1
Q=int(input())
B,C=0,0
P=sum(A)
for i in range(Q):
  B,C=map(int,input().split())
  P+=(C-B)*X[B]
  X[C]+=X[B]
  X[B]=0
  print(P)
