N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [map(int,input().split()) for _ in range(Q)]
B, C = [i for i in zip(*BC)]
#print(B,C)

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

ans = sum(A)
for q in range(Q):
  bc = C(q) - B(q)
  ans = ans + bc * dic.get(B(q),0)
  dic[C(q)] = dic.get(C(q),0) + dic.get(B(q),0)
  dic[B(q)] = 0
  print(ans)
