N=int(input())
z=input()
a=z.split()
A=[]
B=[]
C=[]
for i in range(N):
    A.append(int(a[i]))
Q=int(input())
for j in range(Q):
    d=input()
    D=d.split()
    B.append(int(D[0]))
    C.append(int(D[1]))
A.sort()
for j in range(Q):
    k=0
    while A[k]<=B[j]:
        if A[k]==B[j]:
            A[k]=C[j]
        k+=1
        if k==N:
            break
    A.sort()
    print(sum(A))

