(Stacked bases theorem) If $A$ is a finitely generated free abelian group, and $B$ is a subgroup of $A,$ of the same rank, say $m$, then there is a basis $\{a_{i}: 1 \leq i \leq m \}$ of $A$ and there are elements $d_{1},d_{2},\ldots d_{m}$ of $R$ such that $d_{i} | d_{i+1}$ for each $i$ and $\{ d_{i}a_{i}: 1 \leq i \leq m \}$ is a generating set for $B$.
Some books prove the stacked bases theorem before the structure theorem for finitely generated abelian group. But I wonder how to do it conversely.
If we assume the structure theorem for finite abelian group which shows that $A/B$ is a direct sum of at most $m$ cyclic groups. How to use this fact to show the stacked bases theorem above?