Stable sort for priorities.