List Organization (Renumbering Frames, By X, Y and Z)

Hello everyone, I’m trying to develop a routine that organizes elements (beams) by their coordinates. Based on the following logic:
First, take all the beams on the first floor, then take the parallel beams in X and arrange them in X and then in Y.
Second, take the perpendicular beams at X, arrange them at X and Y.
And then the first step and the second step I can organize (first the parallels in X and then the Perpendiculars in X).
Only then can I go to the next floor after that.

The logic follows:

I tried to follow a similar topic here in the group, but I got several problems handling the lists and sublists, I can put the problems here. (Rename elements (beams,columns etc.) by X and Y direction

I tried to summarize what I need, instead of putting what I already developed, because maybe you can suggest a better flow.

The stage of organizing Parallels in X (X, Y) and Perpendiculars in X (X, Y) I have already developed, what is blocking me and when I will do the analysis with multiple floors.

Tks guys!