#include <cstdio>
#include <queue>

using namespace std;

static const char * itoc
  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\'?";

template<typename T>
static void
push (
  queue<T>    & lis,
  const char  * s
  )
{
  for ( ; *s != '\0'; ++s )
  {
    lis.push ( *s );
  }

  return ;
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  queue<int>  lis;
  int i;

  for ( ; ; )
  {
    const int ch = getchar ( );

    if ( ch == EOF )  break ;
    if ( ch == '\n' )
    {
      while ( !lis.empty ( ) )
      {
        int p = 0;

        for ( i = 0; i < 5; ++i )
        {
          p <<= 1;
          if ( !lis.empty ( ) )
          {
            p |= !!( lis.front ( ) == '1' );
            lis.pop ( );
          }
        }

        putchar ( itoc[ p ] );
      }
      puts ( "" );
      continue ;
    }

    switch ( ch )
    {
      case ' ':   push ( lis, "101" );      break ;
      case '\'':  push ( lis, "000000" );   break ;
      case ',':   push ( lis, "000011" );   break ;
      case '-':   push ( lis, "10010001" ); break ;
      case '.':   push ( lis, "010001" );   break ;
      case '?':   push ( lis, "000001" );   break ;
      case 'A':   push ( lis, "100101" );   break ;
      case 'B':   push ( lis, "10011010" ); break ;
      case 'C':   push ( lis, "0101" );     break ;
      case 'D':   push ( lis, "0001" );     break ;
      case 'E':   push ( lis, "110" );      break ;
      case 'F':   push ( lis, "01001" );    break ;
      case 'G':   push ( lis, "10011011" ); break ;
      case 'H':   push ( lis, "010000" );   break ;
      case 'I':   push ( lis, "0111" );     break ;
      case 'J':   push ( lis, "10011000" ); break ;
      case 'K':   push ( lis, "0110" );     break ;
      case 'L':   push ( lis, "00100" );    break ;
      case 'M':   push ( lis, "10011001" ); break ;
      case 'N':   push ( lis, "10011110" ); break ;
      case 'O':   push ( lis, "00101" );    break ;
      case 'P':   push ( lis, "111" );      break ;
      case 'Q':   push ( lis, "10011111" ); break ;
      case 'R':   push ( lis, "1000" );     break ;
      case 'S':   push ( lis, "00110" );    break ;
      case 'T':   push ( lis, "00111" );    break ;
      case 'U':   push ( lis, "10011100" ); break ;
      case 'V':   push ( lis, "10011101" ); break ;
      case 'W':   push ( lis, "000010" );   break ;
      case 'X':   push ( lis, "10010010" ); break ;
      case 'Y':   push ( lis, "10010011" ); break ;
      case 'Z':   push ( lis, "10010000" ); break ;
    }
  }

  return ( 0 );
}