trigram impl