#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <sstream>
 
using namespace std;
 
const string TASKNAME = "dictionary";
 
string s[123];
int len[123];
int g[123][123], gp[123][123], rg[123][123];
 
int kw, w[123];
int kc, c[123], nc[123];
int small[123];
int n;
bool was[123];
 
void dfs1(int v) {
  was[v] = true;
  for (int j = 0; j < n; j++)
    if (g[j][v] == 0 && !was[j]) dfs1(j);
  w[kw++] = v;
}
 
void dfs2(int v) {
  nc[v] = kc;
  for (int j = 0; j < n; j++)
    if (g[v][j] == 0 && nc[j] == -1) dfs2(j);
}
 
int nt;
int pv[12345];
char pc[12345];
bool edge[123][123];
 
void dfs3(int v, int tt) {
  was[v] = true;
  for (int j = 0; j < n; j++)
    if (!was[j] && edge[v][j]) {
      int up = len[v] - (gp[v][j] + (len[j] - rg[v][j]));
      int t = tt;
      while (up--) t = pv[t];
      for (int u = len[j] - rg[v][j]; u < len[j]; u++) {
        nt++;
        pv[nt] = t;
        pc[nt] = s[j][u];
        t = nt;
      }
      dfs3(j, t);
    }
}
 
bool vis[123];
int itg[123][123][123];
int itc[123][123];
int itkc[123];
bool entered[123];
 
void dfs4(int v, int it) {
  vis[v] = true;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (itc[it][i] == v && !vis[itc[it][j]] && itg[it][i][j] == 0 && !entered[j]) {
        edge[i][j] = true;
        entered[j] = true;
        dfs4(itc[it][j], it);
      }
    }
}
 
int main() {
  freopen((TASKNAME + ".in").c_str(), "r", stdin);
  freopen((TASKNAME + ".out").c_str(), "w", stdout);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  repeat: {  
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (i != j && s[i].find(s[j]) != string::npos) {
          s[j] = s[n - 1];
          n--;
          goto repeat;
        }
  }
  for (int i = 0; i < n; i++) len[i] = s[i].length();
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < n + 1; j++)
      if (i == j) g[i][j] = 12345; else
      if (i == n) g[i][j] = len[j]; else
      if (j == n) g[i][j] = 0; else {
        g[i][j] = len[j];
        gp[i][j] = len[i];
        for (int k = 0; k < len[i]; k++) {
          int cur = len[j];
          for (int p = 0; k + p < len[i] && p < len[j]; p++)
            if (s[i][k + p] == s[j][p]) cur--;
            else break;
          if (cur < g[i][j]) {
            g[i][j] = cur;
            gp[i][j] = k;
          }
        }
      }
  n++;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) rg[i][j] = g[i][j];
  for (int i = 0; i < n; i++) c[i] = i;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) edge[i][j] = false;
  int ans = 1;
  kc = n;
  int iter = 0;
  while (kc > 1) {
    itkc[iter] = kc;
    for (int i = 0; i < n; i++) itc[iter][i] = c[i];
    for (int i = 0; i < kc; i++) small[i] = 123456;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (c[i] != c[j]) {
          if (g[i][j] < small[c[j]]) {
            small[c[j]] = g[i][j];
          }
        }
    for (int i = 0; i < kc; i++) ans += small[i];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (c[i] != c[j]) {
          g[i][j] -= small[c[j]];
        }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) itg[iter][i][j] = g[i][j];
    iter++;
    for (int i = 0; i < n; i++) was[i] = false;
    kw = 0;
    for (int i = 0; i < n; i++)
      if (!was[i]) dfs1(i);
    for (int i = 0; i < n; i++) nc[i] = -1;
    kc = 0;
    for (int i = n - 1; i >= 0; i--)
      if (nc[w[i]] == -1) {
        dfs2(w[i]);
        kc++;
      }
    for (int i = 0; i < n; i++) c[i] = nc[i];
  }
  for (int i = 0; i < n; i++) entered[i] = false;
  entered[n - 1] = true;
  for (int it = iter - 1; it >= 0; it--) {
    for (int i = 0; i < itkc[it]; i++) vis[i] = false;
    for (int i = 0; i < n; i++)
      if (entered[i]) dfs4(itc[it][i], it);
  }
  for (int i = 0; i < n; i++) was[i] = false;
  nt = 1;
  dfs3(n - 1, 1);
  printf("%d\n", nt);
  for (int i = 1; i <= nt; i++)
    if (i == 1) printf("0\n");
    else printf("%d %c\n", pv[i], pc[i]);
  return 0;
}
