Stochastic models on a ring and quadratic algebras. The three-species diffusion problem