In the recent publication [J. Geom. Phys. 33 (2000) 23], we have demonstrated that dynamics of 2+1 gravity can be described in terms of train tracks. Train tracks were introduced by Thurston in connection with description of dynamics of surface automorphisms. In this work, we provide an example of utilization of general formalism developed earlier. The complete exact solution of the model problem describing equilibrium dynamics of train tracks on the punctured torus is obtained. Being guided by similarities between the dynamics of two-dimensional liquid crystals and 2+1 gravity the partition function for gravity is mapped into that for the Farey spin chain. The Farey spin chain partition function, fortunately, is known exactly and has been thoroughly investigated recently. Accordingly, the transition between the pseudo-Anosov and the periodic dynamic regime (in Thurston’s terminology) in the case of gravity is being reinterpreted in terms of phase transitions in the Farey spin chain whose partition function is just the ratio of two Riemann zeta functions. The mapping into the spin chain is facilitated by recognition of a special role of the Alexander polynomial for knots/links in study of dynamics of self-homeomorphisms of surfaces. At the end of paper, using some facts from the theory of arithmetic hyperbolic 3-manifolds (initiated by Bianchi in 1892), we develop systematic extension of the obtained results to noncompact Riemann surfaces of higher genus. Some of the obtained results are also useful for 3+1 gravity. In particular, using the theorem of Margulis, we provide new reasons for the black hole existence in the Universe: black holes make our Universe arithmetic, i.e. the discrete Lie groups of motion are arithmetic.