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))
    for i in range(len(A)):
        if A[i] < B[q]:
            break
        elif A[i] == B[q]:
            A[i] = C[q]
listA.append(sum(A))
for a in range(1,len(listA)):
    print(listA[a])