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

S = [0]*100001
for i in A:
  S[i] += 1

for i in range(Q):
  S[C[i]] += S[B[i]]
  S[B[i]] = 0

  ans = 0

  for i in range(len(S)):
    ans += i*S[i]

  print(ans)