import numpy as np

num_of_numbers = int(input())
numbers = np.array(list(map(int, input().split())))
num_of_operation = int(input())
operations = []
for i in range(num_of_operation):
    operations.append(list(map(int, input().split())))

for operation in operations:
    numbers = np.where(numbers == operation[0], operation[1], numbers)
    print(sum(numbers))