It is given that A and B are two sets such that n(A) = p and n(B) = q.
Now, any element of set A, say ai (1 ≤ i ≤ p), is related with an element of set B in q ways. Similarly, other elements of set A are related with an element of set B in q ways.
Thus, every element of set A is related with every element of set B in q ways.
∴ Total number of functions from A to B = q × q × q × ... × q (p times) = qp