#include<bits/stdc++.h>
using namespace std;
int arr[105][105]={0};
int h,w,k;
void p(){
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
if(arr[i-1][j-1]==-1 || arr[i+1][j-1]==-1 || arr[i-1][j+1]==-1 || arr[i+1][j+1]==-1){
if(arr[i][j]!=1)arr[i][j]=-1;
}
}
}
int f=0;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
if(arr[i][j]==1){
arr[i-1][j]=1;
arr[i+1][j]=1;
arr[i][j-1]=1;
arr[i][j+1]=1;
break;
f=1;
}
}
if(f==1)break;
}
}
int main(){
cin>>h>>w>>k;
//input
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
cin>>arr[i][j];
}
}
//main
for(int i=1;i<=k;i++){
p();
}
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
cout<<arr[i][j]<<" ";
}
cout<<"\n";
}
}
/*
0 -1 0 -1 0
-1 0 -1 0 1
0 -1 0 1 1
-1 0 1 1 1
0 1 1 1 1 */
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGFyclsxMDVdWzEwNV09ezB9OwppbnQgaCx3LGs7CnZvaWQgcCgpewoJZm9yKGludCBpPTE7aTw9aDtpKyspewoJCWZvcihpbnQgaj0xO2o8PXc7aisrKXsKCQkJaWYoYXJyW2ktMV1bai0xXT09LTEgfHwgYXJyW2krMV1bai0xXT09LTEgfHwgYXJyW2ktMV1baisxXT09LTEgfHwgYXJyW2krMV1baisxXT09LTEpewoJCQkJaWYoYXJyW2ldW2pdIT0xKWFycltpXVtqXT0tMTsKCQkJfQoJCX0KCX0KCWludCBmPTA7Cglmb3IoaW50IGk9MTtpPD1oO2krKyl7CgkJZm9yKGludCBqPTE7ajw9dztqKyspewoJCQlpZihhcnJbaV1bal09PTEpewoJCQkJYXJyW2ktMV1bal09MTsKCQkJCWFycltpKzFdW2pdPTE7CgkJCQlhcnJbaV1bai0xXT0xOwo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