program probD;

{$APPTYPE CONSOLE}

const
    maxlen = 20000;
    maxn = 100;

var
   bs, ws : array[1..maxn + maxlen]of string;
   vrq, qsr,vs,son : array[1..maxn ]of longint;
   c:string;
procedure qsort(l,r:longint);
var a,b,t:longint;
begin

   if l > r then exit;
   a := l;
   b := r;
   c := ws[vrq[(l+r)div 2]];
   repeat

     while ws[vrq[a]]< c do inc(a);

     while ws[vrq[b]]> c do dec(b);

     if a <= b then begin
        t:=vrq[a];vrq[a]:=vrq[b];vrq[b]:=t;
        inc(a);
        dec(b);
     end;
   until a > b;

   qsort(a,r);

   qsort(l,b);

end;

var
  m, n,i,j,k,l,p,h1,h2:longint;
begin
  assign(input,'document.in');
  reset(input);
  assign(output,'document.out');
  rewrite(output);
  readln(n);
  i := 0;
  p := 1;
  l := 0;
  while not eof do begin
   inc(i);
   readln(bs[i]);
   if bs[i] = '' then begin
       l := 0;
       inc(p);
       vrq[i] := 0;
   end else begin
       inc(l);
       vrq[i] := l;
   end;
  end;
  m := i;
  k := 0;
  i := 0;
  l :=1 ;
  while i < m do  begin
     inc(i);
    if k = n then begin
       k := 1;
       inc(l);
    end else  inc(k);
     if (vrq[i + 1] = 0)and(k = n) then begin
         qsr[i] := l;
         inc(l);
         inc(i);
         k := 0;
         continue;
     end;
     if (k = n)and(vrq[i] = 1) then begin
         qsr[i] := L + 1;
         inc(l);
         k := 1;
         continue;
     end;
     if (k = n)and(vrq[i] = 2) then begin
          if (i + 2 <= m)and (vrq[i + 2] = 4)then begin
              qsr[i] := l + 1;
              inc(l);
              k := 1;
          end else begin
              qsr[i-1] := l + 1;
              qsr[i] := l + 1;
              inc(l);
              k := 2;
          end;
         continue;
     end;
    qsr[i] := l;
   end;

  p:=0;
  for i := 1 to m do begin
    for j := 1 to length(bs[i]) do
    if upcase(bs[i][j]) in ['A'..'Z'] then begin
      if (j = 1)or not (upcase(bs[i][j-1]) in['A'..'Z']) then begin
        inc(p);
        vs[p] := qsr[i];
        vrq[p]:=p;
      end;
      ws[p] := ws[p] + upcase(bs[i][j]);
    end;
  end;

  qsort(1, p);

  i:=0;

  while i < p do begin
     inc(i);
     j := i - 1;
     write(ws[vrq[i]],' ');
     while (j < p)and(ws[vrq[j + 1]] = ws[vrq[i]])do inc(j);
     l := 0;
     for k := i to j do  begin
       inc(l);
       son[l] := vs[vrq[k]];
     end;

     i := j;

     for h1:=1 to l do
     for h2:=h1+1 to l do
     if son[h1] > son[h2] then begin
         k := son[h1];
         son[h1] := son[h2];
         son[h2] := k;
     end;
     h1 := 0;
     for k:=1 to l do
     if (k=1)or(son[k] > son[k-1])then begin
          inc(h1);
          son[h1]:=son[k];
     end;
     l:=h1;
     k := 1;
     while k <= l do begin
       j := k;
       while (j < l)and(son[j+1] = son[j]+1)do inc(j);
        if j - k + 1 > 2 then begin
           if k>1 then write(',');
           write(son[k],'-',son[j]);
        end else begin
           if k>1 then write(',');
           if j=k+1 then  write(son[k],',');
          write(son[j]);
       end;
        k := j + 1;
     end;
     writeln;
  end;
  close(input);
  close(output);
end.
