N = int(input())
a = list(map(int,input().split()))
Q = int(input())
B = [0]*10**5
C = [0]*10**5

for i in range(Q):
  B[i],C[i] = map(int,input().split())

cou = [0]*10**5
for i in range(1,N+1):
  cou[i] = a.count(i)
allS = sum(a)

for i in range(Q): 
  N_b=0
  N_b = cou[B[i]]
  cou[B[i]] -= N_b
  cou[C[i]] += N_b

  allS = allS + (C[i]-B[i])*N_b
  print(allS)