In the figure displayed in the image below :

To find the remainder on dividing a number by $7$, start at node $0$, for each digit $D$ of the number, move along $D$ black arrows (for digit $0$ do not move at all), and as you pass from one digit to the next, move along a single white arrow.

For example, let $n = 325$. Start at node $0$, move along $3$ black arrows (to node $3$), then $1$ white arrow (to node $2$), then $2$ black arrows (to node $4$), then $1$ white arrow (to node $5$), and finally $5$ black arrows (to node $3$). Finishing at node $3$ shows that the remainder on dividing $325$ by $7$ is $3$.

If you try this for a number that is divisible by $7$, say $63$, you will always end up in node $0$. Therefore, it can also be used to test divisibility by $7$. In case while traversing the digits of number $n$, you end up in the node $0$, $n$ is divisible by $7$, else not.

What exactly is the mathematical explanation for this? Are there such type of graphs for any other integer(s) too?