Var
   i,j,k,m,n,p,t: longint;
   a,b: array [0..51, 0..51] of longint;

Begin
     readln(input,m,n);
     for i:= 1 to m do
         begin
         for j:= 1 to n do
             read(input, a[i,j]);
         readln(input);
         end;
     readln(input,t);
     for k:= 1 to t do
         begin
         for i:= 1 to m do
             for j:= 1 to n do
                 begin
                 p:= 5;
                 b[i,j]:= a[i,j] + a[i-1,j] + a[i+1,j] + a[i,j-1] + a[i,j+1];
                 if (a[i-1,j]= 0) then Dec(p);
                 if (a[i+1,j]= 0) then Dec(p);
                 if (a[i,j-1]= 0) then Dec(p);
                 if (a[i,j+1]= 0) then Dec(p);
                 b[i,j]:= b[i,j] div p;
                 if (odd(b[i,j])) then b[i,j]:= 3*b[i,j] + 1
                                  else b[i,j]:= b[i,j] div 2;
                 end;
         a:= b;
         end;
     for i:= 1 to m do
         begin
         for j:= 1 to n-1 do
             write(output, a[i,j], ' ');
         writeln(output, a[i,n]);
         end;
End.

