> So how one achieves this magic number 7?

The fact that monoids have to be associative heavily constrains the set of possibilities. [This blog post](https://kavigupta.org/2016/07/20/Counting-Monoids/) goes into some detail about counting monoids and similar structures. They give a formula for "pseudomonoids" (which are really [pointed magmas](https://en.wikipedia.org/wiki/Magma_(algebra))) as \\(n \cdot n^{n \cdot n}\\) (read: \\(n\\) choices of point and \\(n^{n \cdot n}\\) choices of binary operator), which can be adapted to account for the behavior of the (fixed) unit as \\(n^{(n-1) \cdot (n-1)}\\). When \\(n = 3\\), this gives exactly your result of \\(81\\), showing that the objects you're counting need not be associative!