Printing lexicographically sorted word