#include<bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
#define endl '\n'
#define ll long long
int n;
string res;
int numPrints = 0;
struct node{
bool type = false;
int numbWords = 0;
node *child[26];
};
node *createNode() {
node *p = new node();
for (int i = 0; i < 26; i++) {
p->child[i] = NULL;
}
return p;
}
void addWord(node *root, string &s, bool ok) {
node *p = root;
for (char c : s) {
if (p->child[c - 'a'] == NULL) {
p->child[c - 'a'] = createNode();
}
p = p->child[c - 'a'];
p->type = ok;
}
p->numbWords++;
}
void dfs(node* root) {
for (int i = 1; i <= root->numbWords; i++) {
res += 'P';
numPrints++;
if (numPrints == n) {
cout << res.size() << endl;
for (int i = 0; i < res.size(); i++) cout << res[i] << endl;
exit(0);
}
}
char chLast = '.';
for (int i = 0; i < 26; i++) {
if (root->child[i] != NULL && root->child[i]->type == true) {
chLast = (char) (i + 'a');
}
}
for (int i = 0; i < 26; i++) {
if (root->child[i] == NULL || (char) (i + 'a') == chLast) {
continue;
}
res += (char) (i + 'a');
dfs(root->child[i]);
res += '-';
}
if (chLast != '.') {
res += chLast;
dfs(root->child[(chLast - 'a')]);
}
}
void solve() {
cin >> n;
vector<string> s(n);
int pos;
int lenMax = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (lenMax < s[i].size()) {
pos = i;
lenMax = s[i].size();
}
}
node *root = createNode();
for (int i = 0; i < n; i++) {
if (i != pos) {
addWord(root, s[i], false);
}
}
addWord(root, s[pos], true);
dfs(root);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("inp.txt","r",stdin);
// freopen("out.txt","w",stdout);
// #endif
solve();
return 0;
}