Let $A,B$ be $n\times n$ matrices with entires in a PID $D$ and $\det AB\neq 0$. Suppose diag$\{a_i\}$, diag$\{b_i\}$, and diag$\{c_i\}$ are normal froms for $A$, $B$, and $AB$. In particular, $a_i|a_{i+1}$. Why must $a_i$ and $b_i$ both divide $c_i$?
I think this requires an application of the structure theorem for modules over a PID, possibly viewing $A$ and $B$ as relations matrices, but I'm not sure how to solve the problem. Any help would be appreciated.
(I am studying for a test -- this is not an exam or homework problem. It is number 5 on page 194 of Jacobson's Basic Algebra I.)