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())))
A_sum=sum(A)
for i in range(Q):
    for j in range(N):
        if BC[i][0]==A[j]:
            A[j]=BC[i][1]
            A_sum+=BC[i][1]-BC[i][0]
    print(A_sum)