Training Markov chains and generating output.