Number of surjective functions from $\{1,2,...,n\}$ to $\{a,b,c\}$ Ok so following questions are given in my text book

Let $A = \{1, 2, 3,...., n\}$ and $B =\{a, b, c\}$ then the number of functions form $A$ to $B$ that are onto is.

I have no idea how to find the answer can anybody help me
Thanks Akash
 A: For a function we know that a unique element from $B$ is assigned to every element of $A$. Therefore counting functions from $A$ to $B$ is the same as counting strings of length $|A|=n$ with elements from $B$.
So then there are $3^n$ functions from $A$ to $B$ in total. To find all surjective functions we must subtract all strings which only consist of elements in $\{a,b\}$ or $\{a,c\}$ or $\{b,c\}$ or only of either of the single elements $a,b$ or $c$. 
Now each time we count the strings consisting of two elements (functions with an image containing only 2 elements in B) we also count two strings consisting of only a single element in B (eg counting strings consisting of {a,b} include counting the two strings only consisting of a and b). So we must subtract 2 strings for every such a case. This gives us all the functions with exactly 2 elements in its image: $3\cdot 2^n-3 \cdot 2$.
Finally we count functions which only have a single element of B in its image (there are only 3).
So then, taking it all together we have, number of functions onto $B$ is \begin{equation} 3^n-(3\cdot 2^n-3\cdot 2)-3. \end{equation} 
