Here is a question from Rotman's Advanced Modern Algebra 3rd edition (page 507, Part 1).
$\mathbf{B}-\mathbf{4 . 6 3}$. If $M$ is a torsion $R$ -module, where $R$ is a PID, prove that $$ \operatorname{Hom}_{R}(M, M) \cong \prod_{(p)} \operatorname{Hom}_{R}\left(M_{(p)}, M_{(p)}\right) $$ where $M_{(p)}$ is the $(p)$ -primary component of $M$.
I can see $$\operatorname{Hom}_{R}(M, M) = \operatorname{Hom}_{R}\left(\bigoplus_{(p)} M_{(p)}, M\right) \cong \prod_{(p)} \ \operatorname{Hom}_{R}\left(M_{(p)}, M\right) $$ by the next two theorems, but I have no idea how to proceed next. Any help would be appreciated.
Attached:
Theorem B-3.38 (Primary Decomposition). If $R$ is a PID, then every torsion $R$ -module $M$ is the direct sum of its $(p)$ -primary components: $$ M=\bigoplus_{(p)} M_{(p)} $$
Theorem B-4.8. Let $R$ be a ring. (i) For every left $R$ -module $A$ and every family $\left(B_{i}\right)_{i \in I}$ of left $R$ -modules, $$ \operatorname{Hom}_{R}\left(A, \prod_{i \in I} B_{i}\right) \cong \prod_{i \in I} \operatorname{Hom}_{R}\left(A, B_{i}\right) $$ via the $\mathbb{Z}$ -isomorphism $\varphi \varphi: f \mapsto\left(p_{i} f\right)\left(p_{i}\right.$ are the projections of the product $\left.\prod_{i \in I} B_{i}\right)$. (ii) For every left $R$ -module $B$ and every family $\left(A_{i}\right)_{i \in I}$ of $R$ -modules, $$ \operatorname{Hom}_{R}\left(\bigoplus_{i \in I} A_{i}, B\right) \cong \prod_{i \in I} \operatorname{Hom}_{R}\left(A_{i}, B\right) $$ via the $\mathbb{Z}$ -isomorphism $f \mapsto\left(f \alpha_{i}\right)\left(\alpha_{i}\right.$ are the injections of the sum $\left.\bigoplus_{i \in I} A_{i}\right)$ (iii) If $A, A^{\prime}, B,$ and $B^{\prime}$ are left $R$ -modules. then there are $\mathbb{Z}$ -isomorphisms $$ \operatorname{Hom}_{R}\left(A, B \oplus B^{\prime}\right) \cong \operatorname{Hom}_{R}(A, B) \oplus \operatorname{Hom}_{R}\left(A, B^{\prime}\right) $$ and $$ \operatorname{Hom}_{R}\left(A \oplus A^{\prime}, B\right) \cong \operatorname{Hom}_{R}(A, B) \oplus \operatorname{Hom}_{R}\left(A^{\prime}, B\right) $$
Hint : For $p\neq q$, can there be a nonzero morphism $M_{(p)}\to M_{(q)}$ ?
Note that $p$ is invertible in $M_{(q)}$.