#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)
for i in range(n):
  X[i] = A.count(i+1)
#print(X)
for i in range(Q):
  B,C = map(int,input().split())
  #print(B,C)
  X[C-1] += X[B-1]
  X[B-1] = 0
  total = 0
  #print(X)
  for j in range(len(X)):
    total += (j+1) * X[j]
  print(total)