#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx = 25005;
vector<string> str;
int n;
map<string,int> dist;
map<string, vector<string>> adj;
map<string, string> pa;
map<string, bool> avoid;
int ct = 0;
int num_weight = 0;
string node = "";
int max_dist = -1;
bool vis = 0;
void solve(string &u) {
if (u != "") cout << u.back() << "\n";
string visit_after = "";
if (adj[u].empty()) {
cout << "P\n";
}
if (u == node) {
vis = 1;
return;
}
for (auto v : adj[u]) {
if (avoid[v]) {
visit_after = v;
continue;
}
solve(v);
if (vis) return;
cout << '-' << "\n";
}
if (visit_after != "") solve(visit_after);
return;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
str.emplace_back(s);
string cur = "";
for (auto x : s) {
adj[cur].emplace_back(cur + x);
pa[cur + x] = cur;
cur += x;
}
}
for (auto [k, v] : adj) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
num_weight += v.size();
}
dist[""] = 0;
queue<string> q;
q.emplace("");
while (!q.empty()) {
auto u = q.front();
q.pop();
for (auto v : adj[u]) {
dist[v] = dist[u] + 1;
q.emplace(v);
}
}
for (auto x : str) {
if (dist[x] > max_dist) {
max_dist = dist[x];
node = x;
}
}
cout << 2 * num_weight - max_dist + n << "\n";
string cur = node;
while (cur != "") {
avoid[cur] = 1;
cur = pa[cur];
}
string empty = "";
solve(empty);
}