#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
  map<char,string> data1;
  map<string,char> data2;

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

  data2["00000"]='A';
  data2["00001"]='B';
  data2["00010"]='C';
  data2["00011"]='D';
  data2["00100"]='E';
  data2["00101"]='F';
  data2["00110"]='G';
  data2["00111"]='H';
  data2["01000"]='I';
  data2["01001"]='J';
  data2["01010"]='K';
  data2["01011"]='L';
  data2["01100"]='M';
  data2["01101"]='N';
  data2["01110"]='O';
  data2["01111"]='P';
  data2["10000"]='Q';
  data2["10001"]='R';
  data2["10010"]='S';
  data2["10011"]='T';
  data2["10100"]='U';
  data2["10101"]='V';
  data2["10110"]='W';
  data2["10111"]='X';
  data2["11000"]='Y';
  data2["11001"]='Z';
  data2["11010"]=' ';
  data2["11011"]='.';
  data2["11100"]=',';
  data2["11101"]='-';
  data2["11110"]='\'';
  data2["11111"]='?';

  while(1){
    string  input="";
    string ans="";
    int kiroku=0;
    int f=0;
    if(!getline(cin,input)) break;
    
    while(1){
      for(int i=kiroku;;i++){
	if(input[i]=='\0'){
	  f=1;
	  break;
	}



	if(input[i]==' ' && input[i+1]==' '){
	  int j;
	  for(j=i+1;;j++){
	    if(input[j]!=' ') break;
	  }
	  kiroku=j;
	  
	  
	  ans+='!';
	  int i, count=0;
	  
	  while(1){
	    string temp="";
	    for(i=0;i<5;i++, count++){
	      if(ans[count]=='!') {
		if(i!=0){
		  for(int j=4;;j--){
		    temp+='0';
		    if(i==j) break;
		  }
		}
		break;
	      }
	      temp+=ans[count];
	    }
	    cout << data2[temp];
	    if(ans[count]=='!') break;
	  }
	  cout << endl;
	  ans="";
	  break;
	}
   




	else ans+=data1[input[i]];
      }
      if(f==1) break;
    }
    
    ans+='!';
    int i, count=0;
    
    while(1){
      string temp="";
      for(i=0;i<5;i++, count++){
	if(ans[count]=='!') {
	  if(i!=0){
	    for(int j=4;;j--){
	      temp+='0';
	      if(i==j) break;
	    }
	  }
	  break;
	}
	temp+=ans[count];
      }
      cout << data2[temp];
      if(ans[count]=='!') break;
    }
    
    cout << endl;
  }

  return 0;
}