Organizing tree based on 2 or more listed items

Hi

I have been trying to structure a tree based on items in tree list.
I need to sort the data in a way that all items from List B be grafts a sub list containing incremental information from list A. And start over when it has reached the highest number in the chain. I then need to use the same sorting on the rest of the information from the two data sources to loft along curve located in the last sources. I can not sort the list numerically because that will mess up the lofting that happens later.

In the example all the items in list B is the same, but that is not necessary the case later.

The structure I need is similar to this.

Sublist 0
B = 207 and A = 207
B = 207 And A = 208

Sublist 1

B = 207 and A = 207
B = 207 And A = 208

I also need this to work if it is sorted like this

Sublist 0
B = 207 and A = 207
B = 207 And A = 208

Sublist 1

B = 201 and A = 205
B = 201 And A = 206

Sorry about the messy explanation, but I have tried this for hours and am really tired.

Sorting list.gh (36.8 KB)