#include <bits/stdc++.h>
using namespace std;
struct Nod {
int cantitate = 0 , urmatorul[26] = { };
pair <int , int> maxim = { };
bool necesar = false;
} arbore[1000000];
int cantitate = 1;
inline void Parcurgere (const int nod)
{
arbore[nod].maxim.second = -1;
for (int indice = 0 ; indice < 26 ; indice++) {
if (arbore[nod].urmatorul[indice])
{
Parcurgere(arbore[nod].urmatorul[indice]);
arbore[nod].cantitate += 1 + arbore[arbore[nod].urmatorul[indice]].cantitate;
arbore[nod].maxim = max(arbore[nod].maxim , {arbore[arbore[nod].urmatorul[indice]].maxim.first + 1 , indice});
}
}
}
inline void Afisare (const int nod , const bool __main)
{
if (arbore[nod].necesar)
{ cout.put('P').put('\n'); }
for (int indice = 0 ; indice < 26 ; indice++) {
if (arbore[nod].urmatorul[indice] && (!__main || indice != arbore[nod].maxim.second))
{
cout.put('a' + indice).put('\n');
Afisare(arbore[nod].urmatorul[indice] , false);
cout.put('-').put('\n');
}
}
if (__main && arbore[nod].maxim.second != -1)
{
cout.put('a' + arbore[nod].maxim.second).put('\n');
Afisare(arbore[nod].urmatorul[arbore[nod].maxim.second] , true);
}
}
inline void Solve ()
{
int necesar;
cin >> necesar;
for (int indice = 1 ; indice <= necesar ; indice++)
{
string sir;
cin >> sir;
int nod = 1;
for (auto& caracter : sir) {
if (!arbore[nod].urmatorul[caracter - 'a'])
{ arbore[nod].urmatorul[caracter - 'a'] = ++cantitate; }
nod = arbore[nod].urmatorul[caracter - 'a'];
}
arbore[nod].necesar = true;
}
Parcurgere(1);
cout << 2 * arbore[1].cantitate - arbore[1].maxim.first + necesar << '\n';
Afisare(1 , true);
}
int main ()
{
ios :: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int numar_teste = 1;
// cin >> numar_teste;
while (numar_teste--)
{ Solve(); }
return 0;
}