#include <iostream>
using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[4] = {0,1,0,-1};
int ddy[4] = {-1,0,1,0};
int ddx2[4]={-1,0,1,0};
int ddy2[4]={0,-1,0,1};
int ddx3[4]={1,0,-1,0};
int ddy3[4]={0,-1,0,1};
int ddx4[4]={0,-1,0,1};
int ddy4[4]={1,0,-1,0};
int ddx5[4]={0,1,0,-1};
int ddy5[4]={-1,0,1,0};
int ddx6[4] = {-1,0,1,0};
int ddy6[4] = {0,1,0,-1};
int ddx7[5] = {0,1,0,-1,0};
int ddy7[5] = {-1,0,1,0,1};
int a[20][20]={0}, vis[20][20]={0};
int main() {
int n, x, y, f, dir = 0, num = 1, c = 0;
cin >> n >> x >> y >> f;
if(f == -1&& y!=0&&y!=n&&x!=n){
for(int i = 0; i < 4; i++){
dx[i] = ddx[i];
dy[i] = ddy[i];
}
}
else if(f == -1&& yn){
for(int i = 0; i < 4; i++){
dx[i] = ddx2[i];
dy[i] = ddy2[i];
}
}
else if(f == -1&& xn){
for(int i = 0; i < 4; i++){
dx[i] = ddx4[i];
dy[i] = ddy4[i];
}
}
else if(f == -1&& y1){
for(int i = 0; i < 4; i++){
dx[i] = ddx4[i];
dy[i] = ddy4[i];
}
}
else if(f == 1&& yn){
for(int i = 0; i < 4; i++){
dx[i] = ddx3[i];
dy[i] = ddy3[i];
}
}
else if(f == 1&& xn){
for(int i = 0; i < 4; i++){
dx[i] = ddx5[i];
dy[i] = ddy5[i];
}
}
if(f == 1&& y1){
for(int i = 0; i < 4; i++){
dx[i] = ddx6[i];
dy[i] = ddy6[i];
}
}
if(f == 1&& y==2){
a[x][y] = vis[x][y] = num++;
while(c <= 4){
int nx = x + ddx7[dir], ny = y + ddy7[dir];
if(vis[nx][ny] || nx < 1 || nx > n || ny < 1 || ny > n){
dir++;
c++;
}else{
c = 0;
a[nx][ny] = num++;
vis[nx][ny] = 1;
x = nx, y = ny;
}
dir %= 5;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
printf("%3d",a[i][j]);
}
cout << endl;
}
return 0;
}
a[x][y] = vis[x][y] = num++;
while(c <= 4){
int nx = x + dx[dir], ny = y + dy[dir];
if(vis[nx][ny] || nx < 1 || nx > n || ny < 1 || ny > n){
dir++;
c++;
}else{
c = 0;
a[nx][ny] = num++;
vis[nx][ny] = 1;
x = nx, y = ny;
}
dir %= 4;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
printf("%3d",a[i][j]);
}
cout << endl;
}
return 0;
}