import numpy as np

n = int(input())
lista = np.array([int(e) for e in input().split()])
q = int(input())



tests = list()
for i in range(q):
    test = [int(e) for e in input().split()]
    tests.append(test)

for i in tests:
    lista = np.where(lista==i[0],i[1],lista)
    print(sum(lista))