N = int(input())
A = sorted(map(int, input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = map( int, input().split() )
    

listA = []
for q in range(Q):
    A = sorted(A)
    listA.append(sum(A))
    index = index_num = [n for n, v in enumerate(A) if v == B[q]]
    for i in index:
        A[i] = C[q]

listA.append(sum(A))
for a in range(1,len(listA)):
    print(listA[a])