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

//®lðQiÌ¶ñ(5P^)ÉÏ·µÄÔ·Ö
string intToBinary(unsigned int n){
	vector<string> temp;
	string binary = "";

	while( n != 0 ){
		(n & 1)? temp.push_back("1") : temp.push_back("0") ;
		n >>= 1;
	}
	for(int i = temp.size()-1 ; i>=0 ; --i){
		binary += temp[i];
	}
	while( binary.size() < 5 ){
		string temp = "0";
		temp += binary;
		binary = temp;
	}
	return binary;
}

int main(){
	map<char,string> table1;
	map<string,char> table2;

	for(int i=0 ; i<32 ; i++){
		if( i < 26 ){
			table1.insert( map<char,string>::value_type( i+'A' , intToBinary(i) ) );
		}else{
			if( i == 26 ) table1.insert( map<char,string>::value_type( ' ' , intToBinary(i) ) );
			if( i == 27 ) table1.insert( map<char,string>::value_type( '.' , intToBinary(i) ) );
			if( i == 28 ) table1.insert( map<char,string>::value_type( ',' , intToBinary(i) ) );
			if( i == 29 ) table1.insert( map<char,string>::value_type( '-' , intToBinary(i) ) );
			if( i == 30 ) table1.insert( map<char,string>::value_type( 39  , intToBinary(i) ) );
			if( i == 31 ) table1.insert( map<char,string>::value_type( '?' , intToBinary(i) ) );
		}
	}

	table2.insert( map<string,char>::value_type( "101"      , ' ' ) );
	table2.insert( map<string,char>::value_type( "000000"   , 39  ) );
	table2.insert( map<string,char>::value_type( "000011"   , ',' ) );
	table2.insert( map<string,char>::value_type( "10010001" , '-' ) );
	table2.insert( map<string,char>::value_type( "010001"   , '.' ) );
	table2.insert( map<string,char>::value_type( "000001"   , '?' ) );
	table2.insert( map<string,char>::value_type( "100101"   , 'A' ) );
	table2.insert( map<string,char>::value_type( "10011010" , 'B' ) );
	table2.insert( map<string,char>::value_type( "0101"     , 'C' ) );
	table2.insert( map<string,char>::value_type( "0001"     , 'D' ) );
	table2.insert( map<string,char>::value_type( "110"      , 'E' ) );
	table2.insert( map<string,char>::value_type( "01001"    , 'F' ) );
	table2.insert( map<string,char>::value_type( "10011011" , 'G' ) );
	table2.insert( map<string,char>::value_type( "010000"   , 'H' ) );
	table2.insert( map<string,char>::value_type( "0111"     , 'I' ) );
	table2.insert( map<string,char>::value_type( "10011000" , 'J' ) );
	table2.insert( map<string,char>::value_type( "0110"     , 'K' ) );
	table2.insert( map<string,char>::value_type( "00100"    , 'L' ) );
	table2.insert( map<string,char>::value_type( "10011001" , 'M' ) );
	table2.insert( map<string,char>::value_type( "10011110" , 'N' ) );
	table2.insert( map<string,char>::value_type( "00101"    , 'O' ) );
	table2.insert( map<string,char>::value_type( "111"      , 'P' ) );
	table2.insert( map<string,char>::value_type( "10011111" , 'Q' ) );
	table2.insert( map<string,char>::value_type( "1000"     , 'R' ) );
	table2.insert( map<string,char>::value_type( "00110"    , 'S' ) );
	table2.insert( map<string,char>::value_type( "00111"    , 'T' ) );
	table2.insert( map<string,char>::value_type( "10011100" , 'U' ) );
	table2.insert( map<string,char>::value_type( "10011101" , 'V' ) );
	table2.insert( map<string,char>::value_type( "0000010"  , 'W' ) );
	table2.insert( map<string,char>::value_type( "10010010" , 'X' ) );
	table2.insert( map<string,char>::value_type( "10010011" , 'Y' ) );
	table2.insert( map<string,char>::value_type( "10010000" , 'Z' ) );

	string str;
	while( cin >> str ){
		string binary = "";
		string temp = "";
		string ans = "";

		for(int i=0 ; i<str.size() ; i++){
			binary += table1[ str[i] ];
		}
		cout << binary << endl;

		while( binary.size() ){
			temp += binary.substr( 0 , 1 );
			binary.erase( binary.begin() );
			if( table2.count(temp) ){
				ans += table2[ temp ];
				temp = "";
			}
		}
		cout << ans << endl;
	}
}