N = int(input())
p = input().split()
p_int = [int(n) for n in p]
Q = int(input())
SUM = sum(p_int)
B2 = 0
for k in range(Q):
  B1, C1 = map(int, input().split())
  if B1 != B2:
    SUM += (C1 - B1) * p_int.count(B1)
    p_int = [C1 if i == B1 else i for i in p_int]
  B2 = B1
  print(SUM)