#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int visited[10][10],n,m,yd[4][2] = {{-1,0},{0,-1},{1,0},{0,1}},sx1,sy1,sx2,sy2,mmx,mmn;
char a[10][10];
queue<int>x,y,mxmn;
int main() {
cin>>m>>n;
for(int i = 1; i <= n; i++) {
scanf("%s",a[i] + 1);
}
cin>>sx1>>sy1>>sx2>>sy2;
if(sx1 <= 0 || sy1 <= 0 || sx2 <= 0 || sy2 <= 0) return 0;
x.push(sx1),y.push(sy1),mxmn.push(2);
x.push(sx2),y.push(sy2),mxmn.push(1);
visited[sx1][sy1] = 2;
visited[sx2][sy2] = 1;
while(!(x.empty() && y.empty() && mxmn.empty())) {
int nx = x.front(),ny = y.front(),nm = mxmn.front();
x.pop(),y.pop(),mxmn.pop();
for(int i = 0; i < 4; i++) {
int tx = nx + yd[i][0],ty = ny + yd[i][1];
if(tx > 0 && ty > 0 && tx <= n && ty <= m) {
if(visited[tx][ty] == 0 && a[tx][ty] == '.') {
visited[tx][ty] = nm;
x.push(tx),y.push(ty),mxmn.push(nm);
if(nm == 2) mmx++;
else if(nm == 1) mmn++;
}
}
}
}
if(mmx == mmn) cout<<"draw"<<endl;
else if(mmx > mmn) cout<<"max"<<endl;
else if(mmx < mmn) cout<<"min"<<endl;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == '#') {
cout<<"#";
}
else cout<<visited[i][j];
}
cout<<endl;
}
}