loop do
	s = gets.chomp
	break if s == ?#
	cand = [s]
	('a'..'z').to_a.reverse.each_cons(2) do |from, to|
		next_cand = []
		cand.each do |s|
			if s =~ /#{to}/
				flag = true
				s.each_char.with_index do |c, i|
					if flag && c == to
						copy = s.dup
						copy[i] = from
						next_cand << copy
					elsif c == from
						flag = false	
						break
					end
				end
				next_cand << s if flag
			else
				next_cand << s if s !~ /#{from}/
			end
		end
		cand= next_cand
	end	
	cand.sort!
	p n = cand.size
	if n <= 10
		puts cand
	else
		puts cand[0..4]
		puts cand[-5..-1]
	end
end