#include <bits/stdc++.h>
using namespace std;
struct Trie {
struct Node {
Node *child[26];
bool is_end;
bool on_path;
Node() {
for(int i=0; i<26; i++) child[i] = 0;
is_end = false;
on_path = false;
}
};
Node *root = new Node();
vector<char> ans;
void insert(string &s) {
Node *cur = root;
for (char c : s) {
int idx = c - 'a';
if (cur->child[idx] == 0) cur->child[idx] = new Node();
cur = cur->child[idx];
}
cur->is_end = true;
}
void mark_longest(string &s) {
Node *cur = root;
for (char c : s) {
int idx = c - 'a';
cur = cur->child[idx];
cur->on_path = true;
}
}
void dfs(Node *cur) {
if (cur->is_end) ans.push_back('P');
int special_child = -1;
for (int i = 0; i < 26; i++) {
if (cur->child[i] == 0) continue;
if (cur->child[i]->on_path) {
special_child = i;
} else {
ans.push_back((char)('a' + i));
dfs(cur->child[i]);
ans.push_back('-');
}
}
if (special_child != -1) {
ans.push_back((char)('a' + special_child));
dfs(cur->child[special_child]);
}
}
void solve(vector<string> &words) {
string longest_str = "";
for (auto &s : words) {
insert(s);
if (s.size() > longest_str.size()) longest_str = s;
}
mark_longest(longest_str);
dfs(root);
cout << ans.size() << "\n";
for (int i=0;i<ans.size();i++){
if ((i+1<ans.size()&&ans[i+1]=='-')){
while(i<ans.size()&&(i+1<ans.size()&&ans[i+1]=='-')||ans[i]=='-'){
cout <<ans[i]<<" ";
i++;
}
i--;
cout <<endl;
}
else
cout<<ans[i]<<endl;
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
if (!(cin >> N)) return 0;
vector<string> words(N);
for (int i = 0; i < N; i++) {
cin >> words[i];
}
Trie t;
t.solve(words);
return 0;
}