For finite abelian groups, show that $G \times G \cong H \times H$ implies $G \cong H$

Let $G$ and $H$ be finite abelian groups such that $G \times G \cong H \times H$.
Then $G \cong H$.

I was going to just write the hypothesis as $G^2 \cong H^2$ and take square roots on both sides, but I don't think that would suffice (and neither would saying "true" a la Myself!)...

The hypothesis tells us that there is an isomorphism, say $f: G \times G\to H \times H$.
I would like to use this to come to the conclusion that there is a bijective homomorphism
$g: G \to H$. (I will be using additive notation...)

Since $f((a, b) + (c, d)) = f(a,b) + f(c, d)$ for all $a,b \in G$ and $c, d \in H$, I was thinking about choosing an arbitrary $a, b \in G$ and calculating:
$$ f((a, 0) + (b, 0)) = f(a, 0) + f(b, 0) \\ \Rightarrow f(a + b, 0) = f(a, 0) + f(b, 0). $$

I basically need to define g in such a way that it extracts the first dimension from the equation. Clearly (I think!), g will invoke f in some way. Can I have a tip on this? It's probably very simple, but I'm not sure how to express it symbolically.

I might not need to show that g is bijective if I can say something to the effect of "this routine verification is straightforward and left to the reader", but I'm afraid I might not be able to perform such a verification if put on the spot! Here's a stab:
f injective $\Leftrightarrow f(a,b) = f(c,d) \Rightarrow (a, b) = (c, d) \Rightarrow a = c \wedge b = d$
So by definition of g (forthcoming...), g(a) = g(c) implies that a = c.

Surjective: For all $x, y \in H$, there exists $a, b \in G : f(a,b) = (x, y)$
Man, this really seems trivial, but without my definition of g, I feel like I'm handwaving...

Thanks again, guys!


Note that it is enough to assume that both $G$ and $H$ are finite $p$ torsion groups for some prime $p$ because under any isomorphism $p$ torsion elements go to $p$ torsion elements and any finite abelian group is direct sum of $p$ torsion groups for finitely many distinct prime $p$. So both $G$ and $H$ have the form $\mathbb{Z}/p^{n_1}\mathbb{Z} \times \mathbb{Z}/p^{n_2}\mathbb{Z} \times \ldots \mathbb{Z}/p^{n_m}\mathbb{Z}$ for some prime $p$. Now you may use structure theorem.