#N,A,Q,B,C
n = 100000
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
#print(N,A,Q)
X = [0]*(n)
total = 0
for i in range(N):
  X[A[i]-1] = A.count(A[i])
  total += A[i]
#for i in range(len(X)):
#	total += (i+1) * X[i] 
#print(X)
for i in range(Q):
  B,C = map(int,input().split())
  #print(B,C)
  total += (C-B)*X[B-1]
  X[C-1] += X[B-1]
  X[B-1] = 0
  print(total)