#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 10;
typedef pair<int, int> pii;
typedef pair<ll, int> pill;
#define fi first
#define se second
const int N = 200005;
struct Node{
Node *child[26];
int cnt;
bool mainPath;
};
Node *createNode(){
Node *tmp = new Node();
for(int i=0;i<26;i++){
tmp->child[i] = NULL;
}
tmp->cnt = 0;
tmp->mainPath = false;
return tmp;
}
Node *root;
int n;
string v[N];
void addString(string &s, bool mark){
Node *p = root;
int len = s.size();
for(int i=0;i<len;i++){
int id = s[i] - 'a';
if(p->child[id] == NULL) p->child[id] = createNode();
p = p->child[id];
if(mark) p->mainPath = true;
}
p->cnt++;
}
string ans = "";
string xauDaiNhat = "";
int maxLen = 0;
int cntLen = 0;
void dfs(Node *p){
for(int i=0;i<p->cnt;i++){
ans += 'P';
cntLen++;
}
int mainId = -1;
for(int id=0;id<26;id++){
if(p->child[id] != NULL && p->child[id]->mainPath){
mainId = id;
break;
}
}
for(int id=0;id<26;id++){
if(p->child[id] == NULL || p->child[id]->mainPath) continue;
ans += id + 'a';
cntLen++;
dfs(p->child[id]);
ans += '-';
cntLen++;
}
if(mainId != -1){
ans += mainId + 'a';
cntLen++;
dfs(p->child[mainId]);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
root = createNode();
cin >> n;
for(int i=0;i<n;i++){
cin >> v[i];
if((int)v[i].size() > maxLen){
maxLen = v[i].size();
xauDaiNhat = v[i];
}
}
for(int i=0;i<n;i++){
addString(v[i], (v[i] == xauDaiNhat));
}
dfs(root);
cout << cntLen << '\n';
for(char c : ans) cout << c << '\n';
return 0;
}