import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
for _ in range(Q):
    b, c = list(map(int, input().split()))
    A[np.where(A==b)] = c
    A = np.sort(A)
    print(np.sum(A))