Hierarchical automata and P systems