As $$999=37\cdot27$$
So, $10^3\equiv1\pmod{37}\implies 10^{3k}\equiv1\pmod{37}$
So, $\sum_{0\le r\le n}a_i10^i$
$$=(a_0+10a_1+100a_2)+10^3(a_3+10a_4+100a_5)+10^6(a_6+10a_7+100a_8)\cdots$$
$$\equiv (a_0+10a_1+100a_2)+(a_3+10a_4+100a_5)+(a_6+10a_7+100a_8)\cdots\pmod {37}$$
i.e., we can group by $3$ digits and add to test the divisibility by $37$
EDIT: the explanation of the link in the Question
As $11\cdot(10a+b)-1\cdot(11b-a)=111\cdot a$
$(10a+b)$ will be divisible by $111\iff (11b-a)$ is divisible by $111$
A more general idea can be found here.
Try to find how $11,1$ are identified as multiplier from the link.