Generalized top sort + test.