#include <bits/stdc++.h>
using namespace std;
struct trie_node {
trie_node* child[26];
int type = 0;
int numbWords = 0;
};
trie_node *root;
int n, numPrints;
int diffractor = -1;
string a[25005];
string ans = "", maxS = "";
trie_node *createNode() {
trie_node* ret = new trie_node();
ret->numbWords = 0;
ret->type = 0;
for (int c = 0; c < 26; c++) {
ret->child[c] = NULL;
}
return ret;
}
void addNode(trie_node* root, const string &s, int te) {
trie_node* p = root;
for (int i = 0; i < (int) s.size(); i++) {
if (p->child[s[i] - 'a'] == NULL) {
p->child[s[i] - 'a'] = createNode();
}
p = p->child[s[i] - 'a'];
p->type = te;
}
p->numbWords++;
}
void print() {
cout << (int) ans.size() << endl;
for (int j = 0; j < (int) ans.size(); j++) {
cout << ans[j] << endl;
}
}
void dfs(trie_node* u) {
for (int i = 1; i <= u->numbWords; i++) {
ans += 'P';
numPrints++;
if (numPrints == n) {
print();
exit(0);
}
}
char lastCh = '.';
for (int c = 0; c < 26; c++) {
if (u->child[c] == NULL) {
continue;
}
if (u->child[c]->type == 1) {
lastCh = (char) (c + 'a');
break;
}
}
for (int c = 0; c < 26; c++) {
if (u->child[c] == NULL || (char) (c + 'a') == lastCh) {
continue;
}
ans += (char) (c+'a');
dfs(u->child[c]);
ans += '-';
}
if (lastCh != '.') {
ans += lastCh;
dfs(u->child[lastCh - 'a']);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
root = createNode();
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
a[i] = s;
if ((int) s.size() > (int) maxS.size()) {
maxS = s;
diffractor = i;
}
}
for (int i = 0; i < n; i++) {
if (i != diffractor) {
addNode(root, a[i], 0);
}
}
addNode(root, a[diffractor], 1);
dfs(root);
return 0;
}