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