program zD1;

{$APPTYPE CONSOLE}

{uses sysutils;}
const alf: set of char = ['a'..'z','A'..'Z'];

type TSet = set of byte;
     TPar =record
              v: array[1..20000] of string[255];
              len: integer;
            end;
     TWord =record
              v: string[255];
              pag: TSet;
            end;
     PWord = array[1..20000] of TWord;

var n, p, l, i: integer;
    par: TPar;
    w: PWord;
    wc: integer;

procedure addword(s: string);
var i: integer;
begin
        for i:=1 to wc do if w[i].v=s then begin
                w[i].pag:=w[i].pag+[p];
                exit;
        end;
        inc(wc); w[wc].v:=s; w[wc].pag:=[p];
end;

procedure addwords(ind: integer);
var s, s1: string[255]; i: integer;
begin
        s:=par.v[ind];
        while s<>'' do begin
                while (not(s[1] in alf)) and (s<>'') do delete(s, 1, 1);
                if s='' then break;
                s1:=''; while (s[1] in alf) and (s<>'') do begin s1:=s1+s[1]; delete(s, 1, 1); end;
                for i:=1 to length(s1) do s1[i]:=upcase(s1[i]);
                addword(s1);
        end;
end;

procedure readpar;
var s: string;
begin
        with par do begin
                len:=0;
                while not eof(input) do begin
                  readln(s); if s='' then break;
                  inc(len); v[len]:=s;
                end;
        end;
end;

procedure outit;
var i, p1, p2, j, k: integer; b: boolean;
begin
        p1:=0; p2:=0;
        for i:=1 to wc do begin
          k:=i; for j:=i+1 to wc do if w[j].v<w[k].v then k:=j;
          write(w[k].v, ' '); b:=false; j:=1;
          while j<=p do begin
             if j in w[k].pag then begin
               if b then write(',') else b:=true;
               write(j); p2:=j;
               while (p2 in w[k].pag) and (p2<=p) do inc(p2); dec(p2);
               if p2>j+1 then begin write('-',p2); j:=p2; end;
             end;
             inc(j);
          end;
          writeln;
          w[k]:=w[i];
        end;
end;

begin
        assign(input, 'document.in'); reset(input);
        assign(output, 'document.out'); rewrite(output);
        readln(n);
        p:=1; l:=0; wc:=0;
        while not eof(input) do begin
                readpar;
                if l+par.len = n+1 then
                        if (par.len=2) or (par.len=3) then begin
                                inc(p); l:=0;
                        end;
                for i:=1 to par.len do begin
                        inc(l); if l>n then begin inc(p); l:=1; end;
                        if ((l=n) and (i=1) and (par.len>1)) or
                           ((l=n) and (i=par.len-1) and (par.len>3)) then
                           begin
                                inc(p); l:=1;
                           end;
                        addwords(i);
                end;
                if l<n then inc(l) else begin inc(p); l:=0; end;
        end;
        outit;
end.
