Lexicographically sort triples.