from sys import stdin
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
P = [list(map(int,stdin.readline().split())) for i in range(Q)]
for i in range(0,Q):
    X=P[i]
    A=list(sorted(A))
    S=A.count(X[0])
    J=A.index(X[0])
    A[J:J+S]=[X[1]]*S
    print(sum(A))