{v$O-,I+,S+,R+,Q+,H-}

{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}

uses sysutils;

const
  cinfile = 'document.in';
  coutfile = 'document.out';
  inf = maxlongint shr 1;
  eps = 1E-8;

  base = 1 shl 16 - 1;
  lmax = 20000;

  alph = ['a'..'z', 'A'..'Z'];

type
  int = longint;
  real = extended;
  float = extended;

  plist = ^tlist;

  tlist = record
    s : string;
    num : int;
    next : plist;
  end;

  plist2 = ^tlist2;
  tlist2 = record
    inf : int;
    next : plist2;
  end;

  trec = record
    num : int;
    s : string;
  end;

  tar = array[1..lmax] of trec;
  tar2 = array[1..lmax] of int;  

var
  n, m, ksl : int;
  hash : array[0..base] of plist;
  ar : array[1..lmax] of plist2;
  ans : int;
  k : int;
  l : array[1..lmax] of string;
  res : tar;
  cur : tar2;

procedure sort(var a : tar2; n : int); overload;
var
  l, r : int;
  x : int;

  procedure sift;
  var
    i, j : int;
  begin
    x := a[l];
    i := l;
    j := i shl 1;
    if (j < r) and (a[j] < a[j + 1]) then inc(j);
    while (j <= r) and (x < a[j]) do
    begin
      a[i] := a[j];
      i := j;
      j := i shl 1;
      if (j < r) and (a[j] < a[j + 1]) then inc(j);
    end;
    a[i] := x;
  end;

begin
  r := n;
  for l := n shr 1 downto 1 do
  begin
    sift;
  end;
  l := 1;
  for r := n-1 downto 1 do
  begin
    x := a[1];
    a[1] := a[r+1];
    a[r+1] := x;
    sift;
  end;
end;

procedure outdata;
var
  i, j, init : int;
  x : plist2;
  f : boolean;
begin
  for i := 1 to ksl do
  begin
    n := 0;
    x := ar[res[i].num];
    while x <> nil do
    begin
      inc(n);
      cur[n] := x^.inf;
      x := x^.next;
    end;
    sort(cur, n);
    init := 1;
    for j := 2 to n do
      if cur[j] <> cur[j - 1] then
      begin
        inc(init);
        cur[init] := cur[j];
      end;
    n := init;
    j := 1;
    write(res[i].s, ' ');
    j := 1;
    f := false;
    while j <= n do
    begin
      init := j;
      while (j < n) and (cur[j + 1] <= cur[j] + 1) do inc(j);
      if cur[j] - cur[init] >= 2 then
      begin
        if f then write(',');
        write(cur[init],'-',cur[j]);
        f := true;
        j := j + 1;
      end else
      begin
        if f then write(',');
        write(cur[init]);
        f := true;        
        j := init + 1;
      end;
    end;
    writeln;
  end;
end;

procedure sort(var a : tar; n : int); overload;
var
  l, r : int;
  x : trec;

  procedure sift;
  var
    i, j : int;
  begin
    x := a[l];
    i := l;
    j := i shl 1;
    if (j < r) and (a[j].s < a[j + 1].s) then inc(j);
    while (j <= r) and (x.s < a[j].s) do
    begin
      a[i] := a[j];
      i := j;
      j := i shl 1;
      if (j < r) and (a[j].s < a[j + 1].s) then inc(j);
    end;
    a[i] := x;
  end;

begin
  r := n;
  for l := n shr 1 downto 1 do
  begin
    sift;
  end;
  l := 1;
  for r := n-1 downto 1 do
  begin
    x := a[1];
    a[1] := a[r+1];
    a[r+1] := x;
    sift;
  end;
end;

function fhash(var s : string) : int;
var
  f, i, p : int;
begin
  f := 0;
  p := 1;
  for i := 1 to length(s) do
  begin
    f := (f + p * ord(s[i])) and base;
    p := (p * 19) and base;
  end;
  f := (f * 133) and base;
  fhash := f;
end;

procedure add_to_list(var list : plist2; inf : int);
var
  x : plist2;
begin
  New(x);
  x^.inf := inf;
  x^.next := list;
  list := x;
end;

procedure push(var s : string; nn : int);
var
  f : int;
  x : plist;
begin
  f := fhash(s);
  x := hash[f];
  while x <> nil do
  begin
    if (x^.s = s) then
    begin
      add_to_list(ar[x^.num], nn);
      exit;
    end;
    x := x^.next;
  end;
  inc(ksl);
  add_to_list(ar[ksl], nn);  
  New(x);
  x^.s := s;
  x^.num := ksl;
  x^.next := hash[f];
  hash[f] := x;
end;

procedure parse(var s : string; nn : int);
var
  i : int;
  w : string;
begin
  i := 1;
  while i <= length(s) do
  begin
    w := '';
    while (i <= length(s)) and not (s[i] in alph) do inc(i);
    while (i <= length(s)) and (s[i] in alph) do
    begin
      w := w + upcase(s[i]);
      inc(i);
    end;
    if w <> '' then push(w, nn);
  end;
end;

procedure solve;
var
  i, j, ptr, nx, lf, num : int;
  s : string;
  x : plist;
begin
  fillchar(hash, sizeof(hash), 0);
  fillchar(ar, sizeof(ar), 0);
  ptr := 1;
  m := 1;
  ksl := 0;
  while true do
  begin
    if seekeof then break;
    k := 0;
    readln(s);
    while trim(s) <> '' do
    begin
      inc(k);
      l[k] := s;
      readln(s);
    end;
    lf := 1;
    num := k;
    while true do
    begin
      if ptr + k - 1 <= n then
      begin
        for i := lf to lf + k - 1 do parse(l[i], m);
        ptr := ptr + k - 1;
        if ptr = n then
        begin
          ptr := 1;
          inc(m);
        end else
        begin
          ptr := ptr + 2;
          if ptr > n then
          begin
            inc(m);
            ptr := 1;
          end;
        end;
        break;
      end;
      nx := lf + n - ptr + 1;
      if (nx = 2) then
      begin
        lf := 1;
        ptr := 1;
        k := num;
        inc(m);
        continue;
      end;
      if nx = num then
      begin
        if num > 3 then
        begin
          for i := lf to num - 2 do parse(l[i], m);
          lf := num - 1;
          ptr := 1;
          k := 2; 
          inc(m);
        end else
        begin
          ptr := 1;
          inc(m);
          k := num;
          lf := 1;
        end;
        continue;
      end;
      for i := lf to nx - 1 do parse(l[i], m);
      lf := nx;
      k := num - nx + 1;
      ptr := 1;
      inc(m);
    end;
  end;

  n := 0;
  for i := 0 to base do
  begin
    x := hash[i];
    while x <> nil do
    begin
      inc(n);
      res[n].num := x^.num;
      res[n].s := x^.s;
      x := x^.next;
    end;
  end;

  sort(res, n);

end;

procedure readdata;
var
  i, j : int;
begin
  readln(n);
end;

begin
  reset(input, cinfile);
  rewrite(output, coutfile);
  readdata;
  solve;
  outdata;
  close(output);
  close(input);
end.
