I have a problem in understanding why we can write the expectation value of an operator $\hat{O}$ as the trace of $\hat{\rho}\hat{O}$ where $\hat{\rho}$ is the density matrix defined for pure state.
In this link: http://www.cithep.caltech.edu/~fcp/physics/quantumMechanics/densityMatrix/densityMatrix.pdf
at page 2, after equation $(8)$, I read the following: $$\langle\hat{O}\rangle= \sum_{m}^{} \sum_{n}^{} a_m^*a_n Q_{mn}= \sum_{m}^{} \sum_{n}^{} \rho_{nm} Q_{mn}= \sum_{n}^{} [\rho Q]_{nn} \quad .$$
I can't understand the last passage, why do we pass from a double sum to a single sum just over $n$?
Here $Q_{mn}$ are the matrix elements of the operator $Q$ with respect to an orthonormal basis ${u_m,u_n,...}$ and $\rho_{nm}$ are the matrix elements of the density matrix again with respect to the same basis, $a_m=\langle u_m|\psi\rangle$ and $u_n=\langle\psi|u_n\rangle$ and $\rho=|\psi\rangle\langle\psi|$.