{$APPTYPE CONSOLE}


type
  TR = record r, c, v: Integer end;
  PR = ^TR;

type
  TCmp = function (var a, b: TR): Integer;

function CmpR(var a, b: TR): Integer;
begin
  if a.r < b.r then Result := -1 else
  if a.r > b.r then Result :=  1 else
  if a.c < b.c then Result := -1 else
  if a.c > b.c then Result :=  1 else Result := 0;
end;

function CmpC(var a, b: TR): Integer;
begin
  if a.c < b.c then Result := -1 else
  if a.c > b.c then Result :=  1 else
  if a.r < b.r then Result := -1 else
  if a.r > b.r then Result :=  1 else Result := 0;
end;

var
  i, N: Integer;
  a: array of TR;

procedure QuickSort(L, R: Integer; pcmp: TCmp);
var
  i, j: Integer;
  p, t: TR;
begin
  repeat
    i := L; j := R;
    p := a[(L + R) shr 1];
    repeat
      while pcmp(a[i], p) < 0 do Inc(i);
      while pcmp(a[j], p) > 0 do Dec(j);
      if i <= j then begin
        t := a[i]; a[i] := a[j]; a[j] := t;
        Inc(i);
        Dec(j);
      end;
    until i > j;
    if L < j then QuickSort(L, j, pcmp);
    L := i;
  until i >= R;
end;

procedure Req;
var
  i, j, nc: Integer;
  ic, v: array of Integer;
begin
  QuickSort(1, N, CmpC);
  SetLength(ic, N + 1);
  nc := 1;
  ic[1] := a[1].c;
  for i := 2 to N do
    if a[i].c <> a[i - 1].c then begin
      Inc(nc); ic[nc] := a[i].c;
    end;
  QuickSort(1, N, CmpR);
  Write(-1:10);
  for i := 1 to nc do Write(ic[i]:10);
  Writeln();
  SetLength(v, N + 1);
  for j := 1 to nc do v[j] := 0;
  j := 1;
  for i := 1 to N do begin
    while a[i].c > ic[j] do Inc(j);
    Inc(v[j], a[i].v);
    if (i = N) or (a[i + 1].r <> a[i].r) then begin
      Write(a[i].r:10);
      for j := 1 to nc do Write(v[j]:10);
      Writeln();
      for j := 1 to nc do v[j] := 0;
      j := 1;
    end;
  end;
end;

begin
//  AssignFile(f, 'input.txt'); Reset(f);
  Read(N);
  SetLength(a, N + 1);
  for i := 1 to N do with a[i] do
    Read(c, r, v);
//  CloseFile(f);
//  AssignFile(f, 'output.txt'); Rewrite(f);
  Req;
  //CloseFile(f);
end.
