Created q(trigram) function computing probability of state trigram