N = int(input())

AAA = list(map(int, input().split()))

Q = int(input())

goukei_AAA = 0
for j in AAA:
  goukei_AAA = goukei_AAA + j

for i in range(0, Q):
    BC = list(map(int, input().split()))
    if not BC[0] in AAA:
        print(goukei_AAA)
        pass
    else:
        how_many_changes = AAA.count(BC[0])

        AAA = [BC[1] if m == BC[0] else m for m in AAA]
        goukei_AAA = goukei_AAA + (how_many_changes * (BC[1] - BC[0]))
        print(goukei_AAA)
