{$APPTYPE CONSOLE}

var
  P: array [1..1000, 1..1000] of Char;
  t, miny, maxx, i, j, N, M, c: Integer;

procedure PR(x, y: Integer; s: String);
var
  i: Integer;
begin
  if y < miny then miny := y;
  i := x + Length(s) - 1;
  if i > maxx then maxx := i;
  for i := 1 to Length(s) do
    P[y, x + i - 1] := s[i];
  Inc(c);
end;

procedure Column(x, y, h: Integer);
var
  cx, cy, i: Integer;
  procedure R(a, b: String);
  begin
    PR(cx, cy, a);
    PR(cx + 5, cy - 1, b);
    PR(cx + 6, cy - 2, a[1]);
    Inc(cy);
  end;
begin
  cx := 4 * (x - 1) + 2 * (y - 1) + 1;
  cy := High(P) - 2 * (y - 1) - 3 * h;
  PR(cx + 2, cy - 2, '+---+');
  PR(cx + 1, cy - 1, '/   /');
  PR(cx, cy, '+---+');
  Inc(cy);
  for i := 1 to h do begin
    R('|   |', ' ');
    R('|   |', ' ');
    R('+---+', '/');
  end;
end;

var
  f: Text;
begin
//  Assign(f, 'input.txt'); Reset(f);
  Read(N, M);
  miny := High(p); maxx := 1;
  FillChar(P, SizeOf(P), '.');
  for j := N downto 1 do
    for i := 1 to M do begin
      Read(t);
      Column(i, j, t)
    end;
//  Close(f);
//  Assign(f, 'output.txt'); Rewrite(f);
  for i := miny to High(P) do
    Writeln(Copy(P[i], 1, maxx));
//  Writeln(c);
//  Close(f);
end.
