import numpy as np

N= int(input())
A= np.array(list(map(int, input().split())))
Q= int(input())

for i in range(Q):
    B, C= list(map(int, input().split()))
    A = A[np.where(A != B)]
    A = np.append(A, np.ones(N - A.shape[0])*C)

    print(int(np.sum(A)))