The input consists of pairs of items (nonempty strings) separated by blanks. Pairs of different items indicate ordering. Pairs of identical items indicate presence, but not ordering.
tsort <<EOF a b c c d e g g f g e f EOF
produces the output:
a b c d e f g