@bozorgi
I clearly understood your project. You are trying to create a wrapper framework on Cypher that is rather user friendly so that one can query Neo4j DB using that wrapper rather than Cypher. The wrapper framework will call Cypher.
To implement that framework your are trying to ingest cypher statements in tree and now you want to traverse the tree.
You can try the solutions given in last post by me of @jaini.kiran.
However I would say that if my understanding is correct, Nodes A,B,C,D,E,.. belong to one Label rather than they distinct Lables.
Traversing the tree can we using with recursive loop please look into the solution provided by @ Andrew in Determine number of node relationships in recursive query - #3 by r.chevalier335