#include<bits/stdc++.h>
#define FT first
#define SC second
#define PB push_back
#define MP make_pair
#define REP(i, l, r) for(int i = (l); i <= (r); i++)
#define PER(i, r, l) for(int i = (r); i >= (l); i--)
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define ROF(i, n) for(int i = (n) - 1; i >= 0; i--)
#define VEP(i, x) for(int i = 0; i < x.size(); i++)
#define DFOR(i, x, y) for(int i = hd[x], y = e[i].to; i; i = e[i].nxt, y = e[i].to)
#define MEM(a, b) memset(a, b, sizeof(a))
#define pos(x, y) ((x - 1) * m + y)
#define rint read<int>()
#define rll read<LL>()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PI;
const int inf = 0x7fffffff;
const int MOD = 1000000007;
template <typename tn>
inline tn read(){
char ch; tn f = 1;
while (!isdigit(ch = getchar())) if (ch == '-') f = -1;
tn x = ch - '0';
while (isdigit(ch = getchar())) x = x * 10 + ch - '0';
return x * f;
}
template <typename tn> inline void cmax(tn &a, tn b){ if (a < b) a = b; }
template <typename tn> inline void cmin(tn &a, tn b){ if (a > b) a = b; }
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int N = 1000000 + 5;
int d[N], color[N], n, m, x, y, l, r;
PI q[N];
int work(int x, int y){
FOR(i, 4){
int tx = x + dx[i], ty = y + dy[i];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= m)
if (color[pos(x, y)] == color[pos(tx, ty)])
if (!~d[pos(tx, ty)] || d[pos(tx, ty)] > d[pos(x, y)]) d[pos(tx, ty)] = d[pos(x, y)], work(tx, ty);
else;
else
if (!~d[pos(tx, ty)]) d[pos(tx, ty)] = d[pos(x, y)] + 1, q[++r] = MP(tx, ty);
}
}
int main(){
//freopen("color.in", "r", stdin);
//freopen("color.out", "w", stdout);
n = rint, m = rint, x = rint, y = rint;
MEM(d, -1);
REP(i, 1, n) REP(j, 1, m) scanf("%d", &color[pos(i, j)]);
for (d[pos(x, y)] = 0, q[l = r = 1] = MP(x, y); l <= r; ++l) work(q[l].FT, q[l].SC);
REP(i, 1, n) REP(j, 1, m) printf("%d%c", d[pos(i, j)], " \n"[j == m]);
}