//2016年CCF第七次测试 俄罗斯方块
// 这道小模拟题还是不错
// 思路:处理出输入矩阵中含1格子的行数和列数
// 再判是否有一个格子碰到底部,否则整体再往下移动一步,如果有一个格子不能移动,要返回到前一步 #include <bits/stdc++.h>
using namespace std;
#define LL long long
const double inf = 123456789012345.0;
const LL MOD =100000000LL;
const int N =1e7+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int g[][],p[][];
int x[],y[];
int main(){
// fre();
for(int i=;i<;i++){
for(int j=;j<;j++){
scanf("%d",&g[i][j]);
}
}
int b;
for(int i=;i<;i++){
for(int j=;j<;j++){
scanf("%d",&p[i][j]);
}
}
int k=;
scanf("%d",&b);
for(int i=;i<;i++){
for(int j=;j<;j++){
if(p[i][j]==){
x[k]=i;
y[k++]=j+b-;
}
}
}
int step=;
int count=;
bool flag=true,flag2=true;
while(flag){
for(int i=;i<;i++){
if(x[i]+step==){
for(int j=;j<;j++){
g[x[j]+step][y[j]]=;
}
flag2=false;
break;
}
if(g[x[i]+step][y[i]]==){
count++;
}
}
if(flag2==false) break;
if(count==){
step++;
count=;
}
else{
for(int i=;i<;i++){
g[x[i]+step-][y[i]]=;
}
flag=false;
}
}
for(int i=;i<;i++){
for(int j=;j<;j++){
printf("%d ",g[i][j]);
}
printf("\n");
}
return ;
}