n = input()
a = [int(i) for i in input().split()]
q = int(input())
bb = []
cc = []
for i in range(q):
    btmp, ctmp = [int(j) for j in input().split()]
    bb.append(btmp)
    cc.append(ctmp)



atol = sum(a)
for b,c in zip(bb,cc):
    
    count = len([ i for i in a  if i == b])
    a = [ c if b == i else i for i in a ]
    atol +=  (c - b) * count
    print(atol)
