program simular_matrixes;

var
  a: array [0..100, 0..100] of longint;
  si, sj, i, j, k, l, m, n, p: longint;

procedure find(x, y: longint; s: longint);
var
  i: longint;
begin
  a[x][y] := a[x][y] + s;
  if s > 0 then
  begin
    for i := 1 to n do
      if (a[i][y] mod p <> 0) and (i <> x) then
      begin
        find(i, y, -s);
        exit;
      end;
  end
  else
  begin
    if x = si then exit;
    for i := 1 to m do
      if (a[x][i] mod p <> 0) and (i <> y) then
      begin
        find(x, i, -s);
        exit;
      end;
  end;
end;

begin
{  assign(input, 'input.txt');
  reset(input);
  assign(output, 'output.txt');
  rewrite(output);}

  read(p, n, m);
  for i := 1 to n do
    for j := 1 to m do
    begin
      read(a[i][j]);
    end;

  for si := 1 to n do
    for sj := 1 to m do
    begin
      while a[si][sj] mod p <> 0 do
        find(si, sj, 1);
    end;

  for i := 1 to n do
  begin
    for j := 1 to m do
      write(a[i][j], ' ');
    writeln;
  end;
end.
