N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = []
for i in range(Q):
    b,c = map(int,input().split())
    BC.append([b,c])

A.sort()
S = []
for i in range(Q):
    for idx in range(N):
        if A[idx] == BC[i][0]:
            A[idx] = BC[i][1]
    S.append(sum(A))

    
for item in S:
    print(item)