#aa=IOBuffer(IJulia.In[59])
readints()=parse.(Int,split(readline()))
readint()=parse.(Int,readline())

N=readint()
A=readints()
Q=readint()
B=zeros(Int,Q)
C=zeros(Int,Q)
for i in 1:Q
    B[i],C[i]=readints()
end


tmp=copy(A)
for i in 1:Q
    tmp[tmp.==B[i]].=C[i]
    println(sum(tmp))
end