Rotational motion for a magnetic moment in a changing magnetic field

If I understand how to do the following problem, it will help with the real complicated problem I am actually doing. The problem I wish to understand is how to derive the equations of motion for a magnetic moment $\vec{m}$ that is in a changing magnetic field $\vec{B}$. I know I can use the Lagrangian to quite easily obtain the equations of motion i.e. the motion of $\ddot{\theta}$ and $\ddot{\phi}$ of the magnetic moment (the reason why I do not want to use the Lagrangian is because the actual problem that I am doing has a piecewise torque function so when the and when integrating the torque to find a potential energy the equation becomes super nasty). Instead I wish to obtain the equations of motion using $\vec{L}=\mathbf{I}\vec{\omega}$ where $\mathbf{I}$ is the moment of inertia tensor. In representing a the magnetic moment as a thin rod, the moment of inertia tensor becomes,

$$\mathbf{I}=\begin{bmatrix} \lambda_1 & 0 & 0 \\ 0 & \lambda_2 & 0 \\ 0 & 0 & 0 \end{bmatrix},$$

where $\lambda_1 = \lambda_2$.

The part that I am getting hung up on is the Euler's equation $\dot{\vec{L}}+\omega \times\vec{L}=\vec{\Gamma}=\vec{m}\times\vec{B}$:

$$\lambda_1\dot{\omega_1}-(\lambda_2 - \lambda_3)\omega_2\omega_3=\Gamma_1,$$ $$\lambda_2\dot{\omega_2}-(\lambda_3 - \lambda_1)\omega_3\omega_1=\Gamma_2,$$ $$\lambda_3\dot{\omega_3}=\Gamma_3,$$

where the $\omega$ terms are in the body frame.

So my question is how to implement the torque when the direction is constantly changing i.e. the magnetic field is a function of time and can be pointing in any direction. If I could get help on this one little spot (since the textbooks seem to have nice torques that are perpendicular to an axis) that would be appreciated.

The relationship between the magnetic moment and the angular momentum is $\vec{m} = \gamma\vec{L}$. Here $\gamma$ is a constant of proportianalit that You can use this to rewrite your EoM as: $$\dot{\vec{L}}+(\vec{\omega}+\gamma \vec{B})\times\vec{L}=0$$ This equation doesn't care if $\vec{B}$ depends on time or not. Just plug in whatever functions you have for the magnetic field as a function of time, and solve the resulting set of coupled differential equations.