Thanks for replying.
Can you sketch a short example of the tree is this case? As I understand it, the moment an end node is encountered, a line should be printed, so you go down the tree to reconstruct the whole sentence, which is "one two one two one two", where the last "two" is the end node.
For test case 5 I still do not see why the output is wrong - there are 5 strings that contain or are "Automaton2000", so five lines are printed in the solution, and they seem to be the right ones following the logic of how the tree is updated.
What am I missing?