N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[]
for i in range(Q):
    BC.append(list(map(int,input().split())))
for i in BC:
    for j in range(N):
        if A[j]==i[0]:
            A[j]=i[1]
    print(sum(A))