def get_hash
  decode = [*("A".."Z").to_a, " ", ".", ",", "-", "'", "?"]
  hash = {" " => "101", "'" => "000000", "," => "000011", "-" => "10010001", "." => "010001", "?" => "000001", "A" => "100101", "B" => "10011010", "C" => "0101", "D" => "0001", "E" => "110", "F" => "01001", "G" => "10011011", "H" => "010000", "I" => "0111", "J" => "10011000", "K" => "0110", "L" => "00100", "M" => "10011001", "N" => "10011110", "O" => "00101", "P" => "111", "Q" => "10011111", "R" => "1000", "S" => "00110", "T" => "00111", "U" => "10011100", "V" => "10011101", "W" => "000010", "X" => "10010011", "Z" => "10010000"}
  return decode, hash
end
class Node
  def initialize(root = nil)
    @root = root || self
    @char = nil
    @children = nil
  end

  def set_child(str, char)
    if str.size == 0
      @char = char
    else
      @children = [Node.new(@root), Node.new(@root)] unless @children
      @children[str[0].to_i].set_child(str[1..-1], char)
    end
  end

  def find(str)
    if str.size == 0
      return ""
    elsif @char
      return @char + @root.find(str)
    elsif @children
      return @children[str[0].to_i].find(str[1..-1])
    else
      return ""
    end
  end
end
def main(input = STDIN)
  decode, hash = get_hash
  root = Node.new
  hash.each{|key, value|
    root.set_child(value, key)
  }
  while arg = input.gets.chomp
    str = ""
    arg.each_char{|char|
      str << decode.index(char).to_s(2).rjust(5, "0")
    }
    puts root.find(str)
  end
end
main