There are several ways of handling this. If you know that you will have a max of 7 under each parent then you could add something as follows:
Parent: A
Children of A: AA, AB, AC, AD, AE, AF, AG
Child of AE: AEA, AEB, AEC, AED, AEF, AEG
and so on.
If you have more than 7 and this can be any number then there are other techniques which require an update of each record in the hierarchy giving it a unique number. I would stick to the easier option above if you are sure with the max 7.
Finding the MAX(id) FROM table WHERE parentid = {id_you_are_searching}
The next entry is the available one for selection.