N = int(input())

Alist = list(map(int,input().split()))
Q = int(input())

Alistreplace = Alist
ans = sum(Alist)
for i in range(Q):
  B,C = map(int,input().split())
  Bnum = Alistreplace.count(B)
  ans = ans+(C-B)*Bnum
  Alistreplace = [C if j==B else j for j in Alistreplace]
  print (ans)
  