An (l,m,n,k) kind Motzkin word is a l+m+n-length word w written with letters from {a,b,0,1,..,k-1} satisfying

This Java applet generates (l,m,n,k) kind Motzkin words in Gray code order: two successive words differ at most in three positions.

Input: l, m<=l, n, k