#include <bits/stdc++.h>
typedef long long ll;
#define M 1000000007
#define N (1 << 18)
using namespace std;
map<char, string> letter_to_code;
map<string, char> code_to_letter;
void init() {
letter_to_code['a'] = "10";
letter_to_code['b'] = "0111";
letter_to_code['c'] = "0101";
letter_to_code['d'] = "011";
letter_to_code['e'] = "1";
letter_to_code['f'] = "1101";
letter_to_code['g'] = "001";
letter_to_code['h'] = "1111";
letter_to_code['i'] = "11";
letter_to_code['j'] = "1000";
letter_to_code['k'] = "010";
letter_to_code['l'] = "1011";
letter_to_code['m'] = "00";
letter_to_code['n'] = "01";
letter_to_code['o'] = "000";
letter_to_code['p'] = "1001";
letter_to_code['q'] = "0010";
letter_to_code['r'] = "101";
letter_to_code['s'] = "111";
letter_to_code['t'] = "0";
letter_to_code['u'] = "110";
letter_to_code['v'] = "1110";
letter_to_code['w'] = "100";
letter_to_code['x'] = "0110";
letter_to_code['y'] = "0100";
letter_to_code['z'] = "0011";
letter_to_code['T'] = "1010"; // Terminator
for (auto [k, v] : letter_to_code) {
code_to_letter[v] = k;
}
}
void encode() {
int k;
cin >> k;
vector<string> words(k);
for (int i = 0; i < k; ++i) {
cin >> words[i];
}
vector<string> res;
for (auto w : words) {
int len = w.size();
string cur;
for (int i = 0; i < len; ++i) {
cur += letter_to_code[w[i]];
cur += "_";
}
cur += letter_to_code['T'];
res.push_back(cur);
}
for (auto x : res) {
cout << x << endl;
}
}
void decode() {
string code;
cin >> code;
vector<string> words;
string curstr;
string cur;
for (int i = 0; i < (int)code.size(); ++i) {
if (code[i] == '_') {
curstr += code_to_letter[cur];
cur = "";
} else {
cur += code[i];
// Terminator
if (cur == "1010") {
words.push_back(curstr);
curstr = "";
cur = "";
}
}
}
cout << words.size() << "\n";
for (auto x : words) {
cout << x << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
init();
if (t == 1) {
encode();
} else {
decode();
}
return 0;
}