Sort to prefer bidirectional links