/*
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[]=new int[1001];
int i,j;
for(i=1;i<=n;i++)
{
arr[i]=sc.nextInt();
}
for(i=1;i<=n;i++)
{
System.out.print(i+": ");
for(j=1;j<=n;j++)
{
if(i!=j)
{
if(arr[i]>arr[j])
{
System.out.print("> ");
}
else if(arr[i]<arr[j])
{
System.out.print("< ");
}
else
{
System.out.print("= ");
}
}
}
System.out.print("\n");
}
}
}
*/
/*
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int map[][]=new int[15][15];
int r,c,i,j,sum=0;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
map[i][j]=sc.nextInt();
}
}
r=sc.nextInt();
c=sc.nextInt();
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
if(map[r][c]==1)
{
sum=-1;
}
else
{
sum=map[r+1][c]+map[r-1][c]+map[r][c+1]+map[r][c-1]+map[r+1][c+1]+map[r-1][c-1]+map[r+1][c-1]+map[r-1][c+1];
}
}
}
System.out.println(sum);
}
}
*/
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a=sc.nextInt(),b=sc.nextInt();
int x=sc.nextInt(),y=sc.nextInt(),z=sc.nextInt();
int k,map[][]=new int[200][200],i,j,i1,sum=0;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
map[i][j]=sc.nextInt();
}
}
k=sc.nextInt();
for(i1=1;i1<=k;i1++)
{
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
sum=map[i+1][j]+map[i-1][j]+map[i][j+1]+map[i][j-1]+map[i+1][j+1]+map[i-1][j-1]+map[i+1][j-1]+map[i-1][j+1];
if(map[i][j]==0)
{
if(sum==x)
{
map[i][j]=1;
}
}
else
{
if(sum>=z||sum<y)
{
map[i][j]=0;
}
}
}
}
}
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
System.out.print(map[i][j]+" ");
}
System.out.print("\n");
}
}
}



