{$APPTYPE CONSOLE}

uses
  Math, SysUtils;

var
  f: TextFile;
  bmp: array[0..1000, 0..1000] of Byte;
  x, y, xc, yc, r, c, Xsize, Ysize, N, i: Integer;
  t: Double;
begin
//  AssignFile(f, 'input.txt'); Reset(f);
  t := Now;
  Read(Xsize, Ysize, N);
  for i := 1 to N do begin
    Read(xc, yc, r, c);
    for y := Max(yc - r, 0) to Min(yc + r, Ysize - 1) do begin
      for x := Max(xc - r, 0) to Min(xc + r, Xsize - 1) do begin
        if Sqr(x - xc) + Sqr(y - yc) <= Sqr(r) then bmp[y, x] := c;
      end;
    end;
  end;
//  CloseFile(f);
//  Writeln(FormatDateTime('nn:ss.nnnn', Now - t));
//  AssignFile(f, 'output.txt'); Rewrite(f);
  for y := 0 to Ysize - 1 do begin
    for x := 0 to Xsize - 1 do begin
      Write(bmp[y, x]);
    end;
    Writeln();
  end;
//  CloseFile(f);
end.
