#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=10009;
struct node {
    set<int>q;
} d[N];
int n,ins[N],c[N],dfn[N],low[N],num,cnt=0;
double ans=0;
vector<int>w[N],w1[N],scc[N];
stack<int>st;
set<int>q;
void Tarjan(int x) {
    dfn[x]=low[x]=++num;
    st.push(x),ins[x]=1;
    for(int i=0; i<w[x].size(); i++) {
        int y=w[x][i];
        if(!dfn[y]) {
            Tarjan(y);
            low[x]=min(low[x],low[y]);
        } else if(ins[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x]) {
        cnt++;
        int y;
        do {
            y=st.top();
            st.pop();
            ins[y]=0;
            c[y]=cnt;
            w1[cnt].push_back(y);
        } while(x!=y);
    }
}
void dfs(int x) {
    d[x].q.insert(x);
    int si=scc[x].size();
    for(int i=0; i<si; i++) {
        int y=scc[x][i];
        if(d[y].q.empty())
            dfs(y);
        for(set<int>::iterator it=d[y].q.begin(); it!=d[y].q.end(); it++)
            d[x].q.insert(*it);
    }
}
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        char a[N];
        scanf("%s",a+1);
        for(int j=1; a[j]!='\0'; j++)
            if(a[j]=='1')
                w[i].push_back(j);
    }
    for(int i=1; i<=n; i++)
        if(!dfn[i])
            num=0,Tarjan(i);
    for(int i=1; i<=n; i++)
        for(int j=0; j<w[i].size(); j++) {
            int x=w[i][j];
            if(c[i]==c[x])
                continue;
            scc[c[x]].push_back(c[i]);
        }
    for(int i=1; i<=cnt; i++) {
        if(d[i].q.empty())
            dfs(i);
    }
    for(int i=1;i<=cnt;i++){
        int res=0;
        for(set<int>::iterator it=d[i].q.begin(); it!=d[i].q.end(); it++)
            res+=w1[(*it)].size();
        ans+=(double)w1[i].size()/res;
    }
    printf("%.13lf",ans);
    return 0;
}
/*
4
0110
1001
0001
0010
*/

#include<bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ick cout << "ickbmi32.9\n"
using namespace std;
struct edge{
    double w = 1;
    int t = 0;
};

edge r[30][30], d[30][30];
int dx[]{0, 0, 1, -1};
int dy[]{1, -1, 0, 0};
char mv[]{'R', 'L', 'D', 'U'};

int getDist(int x, int y, int dir) {
    if(min(x + dx[dir], y + dy[dir]) < 0) return -1;
    if(max(x + dx[dir], y + dy[dir]) >= 30) return -1;
    if(dir == 0) return d[x][y].w;
    if(dir == 1) return d[x][y - 1].w;
    if(dir == 2) return r[x][y].w;
    if(dir == 3) return r[x - 1][y].w;
    return -1;
}

pair<string, vector<pair<int, int>>> path(int x1, int y1, int x2, int y2) {
    double dist[30][30];
    for(int i = 0; i < 30; i++) for(int j = 0; j < 30; j++) dist[i][j] = -1;
    priority_queue<pair<double, pair<int, int>>, vector<pair<double, pair<int, int>>>, greater<>>dij;
    dij.push(mp(0, mp(x1, y1)));
    while(!dij.empty()) {
        pair<double, pair<int, int>> now = dij.top();
        dij.pop();
        if(abs(dist[now.se.fi][now.se.se] + 1) > 1e-5) continue;
        dist[now.se.fi][now.se.se] = now.fi;
        for(int i = 0; i < 4; i++) {
            int di = getDist(now.se.fi, now.se.se, i);
            if(di == -1) continue;
            dij.push(mp(now.fi + di, mp(now.se.fi + dx[i], now.se.se + dy[i])));
        }
    }
    pair<int, int> now = mp(x2, y2);
    vector<pair<int, int>> pa;
    string pam;
    while(now != mp(x1, y1)) {
        //cout << now.fi << ' ' << now.se << endl;
        for(int i = 0; i < 4; i++) {
            int di = getDist(now.fi, now.se, i);
            if(di == -1) continue;
            if(abs(dist[now.fi][now.se] - di - dist[now.fi + dx[i]][now.se + dy[i]]) < 1e-5) {
                pam += mv[i ^ 1];
                now.fi += dx[i];
                now.se += dy[i];
                break;
            }
        }
        pa.pb(now);
    }
    reverse(pa.begin(), pa.end());
    reverse(pam.begin(), pam.end());
    return mp(pam, pa);
}

void upd(string ah, vector<pair<int, int>> ps, double avg) {
    for(int i = 0; i < ah.length(); i++) {
        if(ah[i] == 'D') {
            d[ps[i].fi][ps[i].se].w = (d[ps[i].fi][ps[i].se].w * d[ps[i].fi][ps[i].se].t + avg) / (d[ps[i].fi][ps[i].se].t + 1);
            d[ps[i].fi][ps[i].se].t++;
        }
        if(ah[i] == 'U') {
            d[ps[i].fi][ps[i].se - 1].w = (d[ps[i].fi][ps[i].se - 1].w * d[ps[i].fi][ps[i].se - 1].t + avg) / (d[ps[i].fi][ps[i].se - 1].t + 1);
            d[ps[i].fi][ps[i].se - 1].t++;
        }
        if(ah[i] == 'R') {
            r[ps[i].fi][ps[i].se].w = (r[ps[i].fi][ps[i].se].w * r[ps[i].fi][ps[i].se].t + avg) / (r[ps[i].fi][ps[i].se].t + 1);
            r[ps[i].fi][ps[i].se].t++;
        }
        if(ah[i] == 'L') {
            r[ps[i].fi - 1][ps[i].se].w = (r[ps[i].fi - 1][ps[i].se].w * r[ps[i].fi - 1][ps[i].se].t + avg) / (r[ps[i].fi - 1][ps[i].se].t + 1);
            r[ps[i].fi - 1][ps[i].se].t++;
        }
    }
}
void solve() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    pair<string, vector<pair<int, int>>> go = path(x1, y1, x2, y2);
    double in;
    cout << go.fi << '\n';
    fflush(stdout);
    cin >> in;
    upd(go.fi, go.se, in / go.fi.length());
}
int main() {
    for(int _ = 0; _ < 1000; _++) solve();
}