Homomorphism of Free Groups I am reading the theorem of homomorphism of free group from Fraleigh's text in $\S$36 and could only get a fuzzy idea at best:

Let $G$ be generated by $A = \{a_i \mid i \in I \}$ and let $G'$ be any group. If $a'_i$ for $i \in I$ are any elements in $G'$, not necessarily distinct, then there is at most one homomorphism $\phi : G \to G'$ such that $\phi(a_i) = a'_i.$ If $G$ is free on $A,$ then there is exactly one such homomorphism.

Perhaps someone out there can help me understand by explaining solutions to these two problems under the same section?
(1) How many different homomorphisms are there of a free group of rank 2 into  $\mathbb Z_4$? 
(Here is what I got from the solution manual: There are $4 \times 4 = 16$ homomorphisms because each of the two generator can be mapped into any one of four elements of $\mathbb Z_4$ by the above theorem.)
(2) How many different homomorphisms are there of a free group of rank 2 onto  (a) $\mathbb Z_4$ and (b) $\mathbb Z_6$? 
(Solution manual: Let the free group have generators $x, y.$ By the above theorem, both $x$ and $y$ can be mapped into any elements to give a homomorphism. The homomorphism will be onto $\mathbb Z_4$ if and only if not both $x$ and $y$ are mapped into the subgroup $\{0, 2\}$. Because 4 of the 16 possible homomorphisms map $x$ and $y$ into $\{0, 2\}$, there are $16 - 4 = 12$ homomorphisms onto $\mathbb Z_4.$)
Thank you very much for your time and effort.
 A: Let $A = {a_1,a_2}$ and $G = \langle A\rangle$ a free group of rank $2$.
(1)
By the theorem, a homomorphism $\varphi : G \to \mathbb Z_4$ is uniquely determined by $\varphi(a_1)$ and $\varphi(a_2)$.
Moreover, since $G$ is free on $A$, any combination of $\varphi(a_1)$ and $\varphi(a_2)$ gives rise to a homomorphism.
Since there are $4$ choices for $\varphi(a_1) \in \mathbb Z_4$ and independently $4$ choices for $\varphi(a_2) \in \mathbb Z_4$, the total number of homomorphisms $G \to \mathbb Z_4$ equals $4\cdot 4 = 16$.
(2a)
We have that $\operatorname{im}(\varphi) = \langle \varphi(a_1) ,\varphi(a_2) \rangle$, which is a subgroup of $G$.
The subgroup structure of $\mathbb Z_4$ is
$$\{0\} \subset \{0 , 2\} \subset \mathbb Z_4.$$
So $\operatorname{im}(\varphi) \neq \mathbb Z_4$ if and only if $\operatorname{im}(\varphi) \subseteq \{0 , 2\}$.
By the counting strategy of (1), there are $2\cdot 2 = 4$ such homomorphisms. Thus, the remaining $16 - 4 = 12$ homomorphisms $G \to \mathbb Z_4$ have $\operatorname{im} \varphi = \mathbb Z_4$ (which means they are onto).
(2b)
This is a bit harder than (2a) since the subgroup structure of $G' = \mathbb Z_6$ is a bit more complicated than that of $G' = \mathbb Z_4$.
The proper subgroups of $\mathbb Z_6$ are $H_1 = \{0\}$, $H_2 = \{0,3\}$ and $H_3 = \{0,2,4\}$.
As before, there is $1\cdot 1 = 1$ homomorphism $\varphi$ with $\operatorname{im}\varphi = H_1$. This one is the trivial homomorphism, of course.
There are $2\cdot 2 = 4$ homomorphisms $\varphi$ with $\operatorname{im}\varphi \subseteq H_2$.
Among those homomorphisms, there is the trivial homomorphism with image $H_1$. Since the only further subgroup of $H_2$ is $H_2$, we get that the other $4 - 1 = 3$ homomorphisms have image $H_2$.
Similarly, there are $3^2 - 1 = 8$ homomorphisms with image $H_3$.
Therefore, the number of homomorphisms with image $\mathbb Z_6$ (these are exactly the onto ones) is $6^2 - 1 - 3 - 8 = 24$.
