N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[0]*Q
C=[0]*Q
for i in range(Q):
  B[i], C[i]=map(int,input().split())

num=[0]*(10**5)
for i in range(10**5):
  num[i]=A.count(i+1)
sum=sum(A)
for j in range(Q):
  sum+=num[B[j]-1]*(C[j]-B[j])
  print(sum)
  num[C[j]-1]+=num[B[j]-1]
  num[B[j]-1]=0
