N=int(input())
A=list(map(int,input().split()))
A=list(sorted(A))
Q=int(input())
B=[0]*Q
C=[0]*Q
P = [list(map(int,input().split())) for i in range(Q)]
for i in range(0,Q):
    A=[P[i][1] if j==P[i][0] else j for j in A]
    print(sum(A))