def chash(cycles):
    """
    Hash a cycle, useful for comparing sets of cycles.

    This checks the sorted set of each of the nodes in the cycle. This
    is *not* a perfect check, but it's useful so that we can create a set
    of these hashes, and check that they all match.

    It's not perfect, since D -> A -> B will be the same as B -> A -> D,
    but since this is only used in the testing logic, we can ensure
    that we handle it correctly in the testcases.

    (Implicit warning: Don't use this anywhere important.)
    """
    return {"".join(sorted(set(x))) for x in cycles}