Well, the only way for there to be any one to one functions $A\to B$ is for A to be smaller, ie: $p\leq q$.
In this case, choosing such a function is the same as choosing the $p$ elements of $B$ which are in the image of the map. Thus, the number of such maps is the number of ways to choose $p$ elements out of $q$ where order matters, since we care about the actual function not just it’s image. Thus there are
$\frac{q!}{(q-p)!}$ such maps.
- For onto maps $A\to B$, we now need $A$ to be at least as big as $B$, so $p\geq q$.
After similar counting, we can say that the number of such maps is equal to the number of ways of breaking a $p$ element set into $q$ nonempty subsets, corresponding to the fibers over the elements of $B$.
This is harder. These are called the Stirling numbers of the second kind, $s(p,q)$.