# ans

N = int(input())
A = list(map(int, input().split()))
cnt = [0] * 100000
for i in range(N):
  cnt[i] += 1
Q = int(input())
S = sum(A)

for i in range(Q):
  B, C = map(int, input().split())
  diff = (C - B) * cnt[B]
  S += diff
  print(S)
  cnt[C] += cnt[B]
  cnt[B] = 0