i,j,k,n,m,t:longint;
s:string;
function get_active(i,j:longint):longint;
begin
if a[i+1,j]=1 then inc(get_active);
if a[i-1,j]=1 then inc(get_active);
if a[i,j+1]=1 then inc(get_active);
if a[i,j-1]=1 then inc(get_active);
if a[i+1,j+1]=1 then inc(get_active);
if a[i-1,j-1]=1 then inc(get_active);
if a[i+1,j-1]=1 then inc(get_active);
if a[i-1,j+1]=1 then inc(get_active);
end;
begin
readln(m,n,t);
for i:=1 to m do
begin
readln(s);
for j:=1 to n do a[i,j]:=ord(s[j])-48;
end;
{writeln;}
for i:=1 to m do
begin
a[i,0]:=2;
a[i,n+1]:=2;
end;
for i:=1 to n do
begin
a[0,i]:=2;
a[m+1,i]:=2;
end;
for k:=2 to t do begin
for i:=1 to m do
for j:=1 to n do
begin
if a[i,j]=1 then
case get_active(i,j) of
0,1,4,5,6,7,8:b[i,j]:=0;
2,3:b[i,j]:=1; end
else begin
if get_active(i,j)=3 then b[i,j]:=1 else b[i,j]:=0; end;
end;
a:=b;
end;
for i:=1 to m do
begin
for j:=1 to n do write(a[i,j]);
writeln;
end;
readln;
end.