Amazon Interview Question

generate words from a n *n matrix