import java.io.File;
import java.io.PrintWriter;
import java.util.*;

public class dictionary_gk_mini {
    static Scanner in;
    static PrintWriter out;

    int minId;
    int time;

    Deque<V> stack = new ArrayDeque<>();
    class V {
        List<E> es = new ArrayList<>();
        int e = -1;
        int r;
        boolean v;
        V repr;

        public void visit() {
            v = true;
            e = r = time++;
            stack.add(this);
            for (E e : es) {
                if (e.w == 0) {
                    if (e.v.e == -1) {
                        e.v.visit();
                        r = Math.min(r, e.v.r);
                    } else if (e.v.v) {
                        r = Math.min(r, e.v.e);
                    }
                }
            }
            v = false;

            if (r == e) {
                repr = new V();
                V v;
                do {
                    v = stack.removeLast();
                    v.repr = repr;
                } while (v != this);
            }
        }

        public void build(boolean global, Collection<E> used) {
            v = true;
            for (E e : es) {
                if (e.w == 0) {
                    if (!e.v.v && (global || e.v.repr == repr)) {
                        used.add(e);
                        e.v.build(global, used);
                    }
                }
            }
        }

        public void dump(int id, Set<E> used) {
            for (E e : es) {
                if (used.contains(e)) {
                    if (e.ch != ' ') {
                        int child = ++minId;
                        dictionary_gk_mini.out.println(id + " " + e.ch);
                        e.v.dump(child, used);
                    } else {
                        e.v.dump(id, used);
                    }
                }
            }
        }
    }

    class E {
        V v;
        int w;
        char ch;
        E original;

        E(V v, int w, char ch) {
            this.v = v;
            this.w = w;
            this.ch = ch;
        }

        E(V v, E original) {
            this.v = v;
            this.w = original.w;
            this.original = original;
        }
    }

    void run() {
        int n = in.nextInt();
        String[] ss = new String[n];
        for (int i = 0; i < n; i++) {
            ss[i] = in.next();
        }

        for (String s : ss) {
            for (int i = 0; i < s.length() + 1; i++) {
                V p = v(s.substring(0, i));
                if (i != 0) {
                    v(s.substring(0, i - 1)).es.add(new E(p, 1, s.charAt(i - 1)));
                }
                for (int j = 1; j < i; j++) {
                    V v = v(s.substring(j, i));
                    p.es.add(new E(v, 0, ' '));
                    p = v;
                }
            }
        }

        Set<E> es = chinese(v(""), vertices.values());
        int c = 1;
        for (E e : es) {
            if (e.ch != ' ') {
                c++;
            }
        }

        out.println(c);
        out.println(0);
        v("").dump(++minId, es);
    }

    Set<E> chinese(V r, Collection<V> vs) {
        Map<V, Integer> mws = new HashMap<>();
        for (V v : vs) for (E e : v.es) mws.put(e.v, mws.containsKey(e.v) ? Math.min(mws.get(e.v), e.w) : e.w);
        for (V v : vs) for (E e : v.es) e.w -= mws.get(e.v);

        r.visit();
        boolean all = true;
        for (V v : vs) if (v.e == -1) {
            v.visit();
            all = false;
        }

        Set<E> used = new HashSet<>();
        if (all) {
            r.build(true, used);
            return used;
        }

        Set<V> cond = new HashSet<>();
        for (V v : vs) cond.add(v.repr);
        for (V v : vs) for (E e : v.es) if (v.repr != e.v.repr) v.repr.es.add(new E(e.v.repr, e));

        r.build(false, used);
        for (E e : chinese(r.repr, cond)) {
            used.add(e.original);
            e.original.v.build(false, used);
        }
        return used;
    }

    Map<String, V> vertices = new HashMap<>();
    V v(String s) {
        V v = vertices.get(s);
        if (v == null) {
            v = new V();
            vertices.put(s, v);
        }
        return v;
    }

    public static void main(String[] args) throws Exception {
        in = new Scanner(new File("dictionary.in"));
        out = new PrintWriter("dictionary.out");

        new dictionary_gk_mini().run();

        in.close();
        out.close();
    }
}
