#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vc = vector<char>;
using vcc = vector<vc>;
using Pii = pair<int,int>;
using ld = long double;



int main(){
    int h,w,x,y;
    cin >> h >> w >> x >> y;
    vvi V(200, vi(200,0));
    for(int i = 0; i<h; i++){
        for(int j = 0; j<w; j++){
            char c;
            cin >> c;
            if(c=='#'){
                V[i][j] = 1;
            }
        }
    }
    int ans = 0;
    for(int i = x-2; i>=0; i--){
        if(V[i][y-1]){
            break;
        }
        else{
            ans++;
        }
    }
    for(int i = x; i<h; i++){
        if(V[i][y-1]){
            break;
        }
        else{
            ans++;
        }
    }
    for(int j = y-2; j>=0; j--){
        if(V[x-1][j]){
            break;
        }
        else{
            ans++;
        }
    }
    for(int j = y; j<w; j++){
        if(V[x-1][j]){
            break;
        }
        else{
            ans++;
        }
    }
    cout << ans+1 << endl;
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << "{ " << p.first << ',' << p.second << " } ";
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e: v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e: v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

int n, m;
V<string> s;

// fstream out("AHC004_out.txt");

int main() {

    clock_t start = clock();

    cin >> n >> m;
    s.resize(m);
    cin >> s;

    V<P> cnts(m); // pair = (count, index);
    V<V<int>> ins(m);

    rep(i,m) {
        int cnt = 0;
        rep(j,m) {
            bool isin = ( s[i].find(s[j]) != string::npos );
            if(isin) {
                cnt++;
                ins[i].push_back(j);
            }
        }
        cnts[i] = make_pair(cnt,i);
    }
    sort(rall(cnts));

    V<bool> used(m);
    V<string> ans(n);

    rep(i,n) { // 初期解生成
        string str = "";
        rep(j,m) {
            int x = cnts[j].se;
            if(used[x]) continue;
            string plus = s[x];
            for(int k = min(sz(str), sz(s[x])); k >= 0; k--) {
                if( str.substr(sz(str)-k,k) == s[x].substr(0,k) ) {
                    plus = s[x].substr(k,sz(s[x])-k);
                    break;
                }
            }
            if(sz(str) + sz(plus) > n) continue;
            str += plus;
            for(int y: ins[x]) used[y] = true;
        }
        str.resize(n,'.');
        ans[i] = str;
    }

    V<int> v(n); iota(all(v), 0);
    pair<int,V<int>> mx = make_pair(0,v);

    random_device seed_gen;
    mt19937 engine(seed_gen());

    while(clock() - start < 2980) {
        V<bool> nused = used;
        int cnt = 0;
        rep(i,n) {
            string ns = "";
            rep(j,n) ns += string(1,ans[v[i]][j]);
            ns += ns;
            rep(j,m) {
                if(nused[j]) continue;
                if( ns.find(s[j]) != string::npos ) {
                    cnt++;
                    nused[j] = true;
                }
            }
        }
        chmax(mx, make_pair(cnt, v));
        shuffle(all(v), engine);
    }

    rep(i,n) {
        cout << ans[mx.se[i]] << endl;
    }
}