set tmp_lst {}
set fp [open "test.txt"]
while {[gets $fp str] != -1} {
	lappend tmp_lst [string reverse $str]
}
close $fp
set all_lst {}
foreach str [lsort -decreasing $tmp_lst] {
	set str [string reverse $str]
	set str_len [string length $str]
	while {true} {
		set all_str [join $all_lst "\0"]
		set all_len [string length $all_str]
		set pos [string last $str $all_str]
		if {($pos != -1) &&
		    [expr {($pos + $str_len) == $all_len}]} then { break }
		lappend all_lst $str
	}
	puts $pos
}
puts all_lst
puts [join $all_lst "\n"]
