I'm trying to understand how to apply tensor products on 3-qubit systems (or well at least 2 qubits). Let's take a basic example:
where $$\lvert \psi \rangle = \lvert q_2q_1q_0\rangle $$ with $q_2$ being the most significant bit and $q_0$ the least significant (matching the above schematic for the circuit).
H matrix (for a single qubit): $$H = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} $$
I understand that I need to use the identity matrix and tensor product in order to format the Hadamard matrix (and any other in the circuit) to be applied to 3 qubits. What I do not understand is how, generally, I determine the order of the tensor product? In order words, with the above description, should I do:
$$M=(H\otimes I)\otimes I = \frac{1}{\sqrt{2}} \begin{bmatrix} I & 0 & I & 0\\ 0 & I & 0 & I\\ I & 0 & -I & 0\\ 0 & I & 0 & -I\\ \end{bmatrix}$$
or
$$M=(I\otimes I)\otimes H = \begin{bmatrix} H & 0 & 0 & 0\\ 0 & H & 0 & 0\\ 0 & 0 & H & 0\\ 0 & 0 & 0 & H\\ \end{bmatrix}$$
More generally, how should I think about why the correct one is the right one? What is the logic I need to understand with regards to the "extension" of my gate's matrices and in which order I need to apply the Identity matrices in the tensor product?