/*#include<stdio.h>
int main()
{
int i, j, n, x[100] = {}, y[100] = {}, a, b;
int arr[100][100] = {};
for(i=0; i<=11; i++)
{
for(j=0; j<=11; j++)
{
arr[i][j] = -1;
}
}
for(i=1; i<=10; i++)
{
for(j=1; j<=10; j++)
{
scanf("%d", &arr[i][j]);
}
}
scanf("%d", &n);
for(i=0; i<n; i++)
scanf("%d %d", &x[i], &y[i]);
for(i=1; i<=10; i++)
{
for(j=1; j<=10; j++)
{
if(arr[i][j]>0)
{
b=1;
for(a=0; a<arr[i][j]; a++)
{
if(arr[i][j+b]!=-1&&arr[i][j+b]<=0)
{
arr[i][j+b] = -2;
b++;
}
else if(arr[i][j+b]>0)
{
b++;
}
else
break;
}
b=1;
for(a=0; a<arr[i][j]; a++)
{
if(arr[i][j-b]!=-1&&arr[i][j-b]<=0)
{
arr[i][j-b] = -2;
b++;
}
else if(arr[i][j-b]>0)
{
b++;
}
else
break;
}
b=1;
for(a=0; a<arr[i][j]; a++)
{
if(arr[i+b][j]!=-1&&arr[i+b][j]<=0)
{
arr[i+b][j] = -2;
b++;
}
else if(arr[i+b][j]>0)
{
b++;
}
else
break;
}
b=1;
for(a=0; a<arr[i][j]; a++)
{
if(arr[i-b][j]!=-1&&arr[i-b][j]<=0)
{
arr[i-b][j] = -2;
b++;
}
else if(arr[i-b][j]>0)
{
b++;
}
else
break;
}
arr[i][j] = -2;
}
}
}
for(i=0; i<n; i++)
{
if(arr[x[i]][y[i]]!=-2)
{
arr[x[i]][y[i]] = i+1;
}
}
for(i=1; i<=10; i++)
{
for(j=1; j<=10; j++)
{
printf("%d ", arr[i][j]);
}
printf("\n");
}
printf("Character Information");
for(i=0; i<n; i++)
{
printf("\n");
if(arr[x[i]][y[i]]==-2)
printf("player %d dead", i+1);
else
printf("player %d survive", i+1);
}
return 0;
}*/
#include<stdio.h>
int main()
{
int a, b, x, y, z, k, i, j;
int arr1[100][100] = {}, arr2[100][100] = {};
int c, d;
scanf("%d %d", &a, &b);
scanf("%d %d %d", &x, &y, &z);
for(i=1; i<=a; i++)
{
for(j=1; j<=b; j++)
{
scanf("%d", &arr1[i][j]);
}
}
scanf("%d", &k);
for(d=0; d<k; d++)
{
for(i=1; i<=a; i++)
{
for(j=1; j<=b; j++)
{
if(arr1[i][j]==1)
{
c = arr1[i+1][j+1] + arr1[i+1][j] + arr1[i][j+1] + arr1[i+1][j-1] + arr1[i-1][j+1] + arr1[i-1][j-1] + arr1[i-1][j] + arr1[i][j-1];
//printf("%d\n", c);
if(z>y)
{
if(c >= y)
arr2[i][j]=1;
if(c >= z)
arr2[i][j]=0;
}
else if(y>z)
{
if(c >= z)
arr2[i][j]=0;
if(c >= y)
arr2[i][j]=1;
}
}
else if(arr1[i][j]==0)
{
c = arr1[i+1][j+1] + arr1[i+1][j] + arr1[i][j+1] + arr1[i+1][j-1] + arr1[i-1][j+1] + arr1[i-1][j-1] + arr1[i-1][j] + arr1[i][j-1];
//printf("%d\n", c);
if(c == x)
arr2[i][j]=1;
}
}
}
for(i=1; i<=a; i++)
{
for(j=1; j<=b; j++)
{
arr1[i][j] = arr2[i][j];
}
}
}
for(i=1; i<=a; i++)
{
for(j=1; j<=b; j++)
{
printf("%d ", arr2[i][j]);
}
printf("\n");
}
}



