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() )
    
    
def index_Multi(List,liter):
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L

listA = []
for q in range(Q):
    A = sorted(A)
    listA.append(sum(A))
    index = index_Multi(A,B[q])
    for i in index:
        A[i] = C[q]

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