Extending automaton to calculate prefixes and suffixes of any given state.