Fix find_pair logic to support matching roots for different pairs