How to connect lines that in random order in two continuous polylines


I have inner continous edge and outer continous edge. but sub-edges have random order.

How to filter/sort them out to create 2 polylines - one for outer edge and one for inner edge?

sorting_curves.3dm (56.2 KB)

the JoinCurves command does not require a order (4.1 KB)