#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cout << #a << ": " << a << endl;
#define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl;
#define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; }
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }
struct room {
    int r[17][17]{};
    int na{};
};
int main() {
    fastio;
    ll ans{};
    ll H,W,A,B;
    cin >> H >> W >> A >> B;
    auto nxt = [&](int i, int j)->pair<int,int> {
        if (j == W-1) {
            j = 0;
            ++i;
            return {i,j};
        }
        return {i,j+1};
    };
    function<void(room,int,int)> dfs = [&](room r,int i, int j) {
        if (i == H) {
            ll t=0;
            rep(k,H) rep(l,W) {
                if (r.r[k][l] > 0) ++t;
            }
            if (t == A*2) {
                ++ans;
            }
            return;
        }
        auto [ni,nj] = nxt(i,j);
        if (r.r[i][j] > 0) {
            dfs(r, ni,nj);
            return;
        }
        dfs(r, ni,nj);
        room q = r;
        if (j<W-1 && r.r[i][j+1] == 0) {
            r.r[i][j] = 1;
            r.r[i][j+1] = 1;
            dfs(r,ni,nj);
        }
        if (i<H-1 && r.r[i+1][j] == 0) {
            q.r[i][j] = 1;
            q.r[i+1][j] = 1;
            dfs(q,ni,nj);
        }
    };
    dfs(room{}, 0,0);
    cout << ans << endl;
}

#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << (x) << "\n"
using namespace std;
int si, sj, t[60][60], p[60][60], M;
bool b1[50 * 51];
int score(string s) {
	int xs = si, ys = sj, r = p[xs][ys];
	for (char c : s) {
		if (c == 'U')xs--;
		if (c == 'D')xs++;
		if (c == 'L')ys--;
		if (c == 'R')ys++;
		r += p[xs][ys];
	}
	return r;
}
char fr1(int pu, int pd, int pl, int pr) {
	int r = rand() % (pu + pd + pl + pr);
	if (r < pu)return 'U';
	if (r < pu + pd)return 'D';
	if (r < pu + pd + pl)return 'L';
	return 'R';
}
int main() {
	srand((unsigned)time(NULL));
	cin >> si >> sj; si++; sj++; b1[2525] = 1;
	for0(i, 52)for0(j, 52) {
		if (i * j == 0 || i == 51 || j == 51)t[i][j] = 2525;
		else { cin >> t[i][j]; M = max(M, t[i][j]); }
	}
	for1(i, 50)for1(j, 50)cin >> p[i][j];
	string s1 = ""; int v1 = score(s1), ti = clock();
	while (clock() - ti <= 1800000) {
		string sp = "";
		int xi = si, yi = sj;
		while (1) {
			b1[t[xi][yi]] = 1;
			int pu = 10; for1(i, 10)if (b1[t[xi - i][yi]]) { pu = i - 1; break; }
			int pd = 10; for1(i, 10)if (b1[t[xi + i][yi]]) { pd = i - 1; break; }
			int pl = 10; for1(i, 10)if (b1[t[xi][yi - i]]) { pl = i - 1; break; }
			int pr = 10; for1(i, 10)if (b1[t[xi][yi + i]]) { pr = i - 1; break; }
			if (pu + pd + pl + pr == 0)break;
			char rc = fr1(pu, pd, pl, pr); sp += rc;
			if (rc == 'U')xi--;
			if (rc == 'D')xi++;
			if (rc == 'L')yi--;
			if (rc == 'R')yi++;
		}
		int vi = score(sp);
		if (vi > v1) {
			s1 = sp; v1 = vi;
		}
		for0(i, M)b1[i] = 0;
	}
	puts(s1);
}