var
m,n,t,i,j,k,tot:longint;
s:string;
a,b:array [1..1000,1..1000] of 0..1;
begin
readln(m,n,t);
for i:=1 to n do
begin
readln(s);
for j:=1 to m do
a[i,j]:=ord(s[j])-ord('0');
end;
for i:=1 to t-1 do
begin
for j:=1 to n do
for k:=1 to m do
begin
tot:=0;
if a[j,k]=0 then
begin
if (j>1) and (a[j-1,k]=1) then inc(tot);
if (k>1) and (a[j,k-1]=1) then inc(tot);
if (j<n) and (a[j+1,k]=1) then inc(tot);
if (k>m) and (a[j,k+1]=1) then inc(tot);
if (j>1) and (k>1) and (a[j-1,k-1]=1) then inc(tot);
if (j<n) and (k<m) and (a[j+1,k+1]=1) then inc(tot);
if (j>1) and (k<m) and (a[j-1,k+1]=1) then inc(tot);
if (j<n) and (k>1) and (a[j+1,k-1]=1) then inc(tot);
if tot=3 then b[j,k]:=1
else b[j,k]:=0;
end
else
begin
if (j>1) and (a[j-1,k]=1) then inc(tot);
if (k>1) and (a[j,k-1]=1) then inc(tot);
if (j<n) and (a[j+1,k]=1) then inc(tot);
if (k>m) and (a[j,k+1]=1) then inc(tot);
if (j>1) and (k>1) and (a[j-1,k-1]=1) then inc(tot);
if (j<n) and (k<m) and (a[j+1,k+1]=1) then inc(tot);
if (j>1) and (k<m) and (a[j-1,k+1]=1) then inc(tot);
if (j<n) and (k>1) and (a[j+1,k-1]=1) then inc(tot);
if (tot=3) or (tot=2) then b[j,k]:=1
else b[j,k]:=0;
end;
end;
a:=b;
end;
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]);
writeln;
end;
readln;
readln
end.