sorting cycles by their order