program voc_ka_new;

{$APPTYPE CONSOLE}
{$MAXSTACKSIZE 1000000000}
//{$D-,I-,L-,Q-,R-,S-,O+}
{$D+,I+,L+,Q+,R+,S+,O-}
uses
  SysUtils;

const len = 15;
const nmax = 100 * 1000 + 5;
const magic = 1000;

type TWord = string[len];

type TDet = record
              cnt,first,last:integer;
            end;  

type TSymb = record
               way:char;
               ans,vertex,next:integer;
             end;
type TAns = record
              value,next:integer;
            end;  

var p,cnt_det,cnt_ans,n,i,v,cnt_symb:integer;
    symb:array [-1..len*nmax] of TSymb;
    ans:array [1..nmax] of TAns;
    wor,tran:array [1..nmax] of TWord;
    det:array [1..nmax] of TDet;
    q:TWord;
    c:char;
    flag:boolean;
    
procedure add_c(c:char);
var q,p,t:integer;
begin
  t:=symb[v].vertex;
  while t<>-1 do
  begin
    if symb[t].way = c then
    begin
      v:=t;
      exit;
    end;
    t:=symb[t].next;
  end;
  p:=symb[v].vertex;
  while (symb[p].next<>-1) and (symb[symb[p].next].way < c) do
    p:=symb[p].next;
  if symb[p].way>c then
  begin
    q:=p;
    p:=-1;
  end else
    q:=symb[p].next;
  inc(cnt_symb);
  symb[cnt_symb].ans:=0;
  symb[cnt_symb].way:=c;
  symb[cnt_symb].vertex:=-1;
  symb[cnt_symb].next:=q;
  if p<>-1 then
    symb[p].next:=cnt_symb
  else
    symb[v].vertex:=cnt_symb;
  v:=cnt_symb;
end;

procedure add_w(v,s:integer);
begin
  inc(cnt_ans);
  v:=symb[v].ans;
  inc(det[v].cnt);
  ans[cnt_ans].value:=s;
  ans[cnt_ans].next:=-1;
  if det[v].last <> -1 then
    ans[det[v].last].next:=cnt_ans;
  if det[v].first = -1 then
    det[v].first:=cnt_ans;
  det[v].last:=cnt_ans;
end;

procedure print_ans(v:integer);
var k:integer;
begin
  v:=symb[v].ans;
  write(tran[v], ' - ');
  k:=det[v].first;
  while k<>-1 do
  begin
    if ans[k].next <> -1 then
      write(wor[ans[k].value], ', ')
    else
      writeln(wor[ans[k].value]);
    k:=ans[k].next;
  end;
end;

procedure pass(v:integer);
var t:integer;
begin
  if symb[v].ans<>0 then
    print_ans(v);
  t:=symb[v].vertex;
  while t<>-1 do
  begin
    pass(t);
    t:=symb[t].next;
  end;
end;

begin           
//  reset(input,'voc.in');
//  rewrite(output,'voc.out');

  readln(n);
  cnt_det:=0;
  cnt_ans:=0;

  symb[-1].next:=-1;
  symb[1].vertex:=-1;
  symb[1].ans:=0;
  symb[1].next:=-1;
  cnt_symb:=1;
  for i:=1 to n do
  begin
    flag:=true;
    wor[i]:='';
    read(c);
    while c in ['a'..'z'] do
    begin
      wor[i]:=wor[i]+c;
      read(c);
    end;
    read(c);
    read(c);
    while (not eoln) and (flag) do
    begin
      q:='';
      read(c);
      while (c in ['a'..'z']) do
      begin
        q:=q+c;
        read(c);
      end;             
      if ord(c) < 32 then
      begin
        readln;
        flag:=false;
      end
      else
        read(c);
      v:=1;
      for p:=1 to length(q) do
        add_c(q[p]);

      if symb[v].ans=0 then
      begin
        inc(cnt_det);
        symb[v].ans:=cnt_det;
        tran[cnt_det]:=q;
        det[cnt_det].first:=-1;
        det[cnt_det].cnt:=0;
        det[cnt_det].last:=-1;
      end;
      add_w(v,i);
    end;
  end;

  writeln(cnt_det);
  pass(1);

  close(input);
  close(output);
end.