#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< >(b,vector(c,d)) #define vvv(a,b,c,d,e) vector > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair; using vi = vector; using vll = vector; template vector > mulMat(const vector > &A, const vector > &B) { auto n = A.size(), m = A[0].size(), p = B[0].size(); vector > res(n, vector(p)); for (int i = 0; i < n; ++i)for (int j = 0; j < p; ++j) for (int k = 0; k < m; ++k) res[i][j] += A[i][k] * B[k][j]; return res; } template vector > powMat(vector > A, long long k) { auto n = A.size(); vector > res(n, vector(n)); for (int i = 0; i < n; ++i)res[i][i] = 1; while (k) { if (k % 2)res = mulMat(res, A); k /= 2; A = mulMat(A, A); } return res; } const int DY[] = { -1,0,1,0 }; const int DX[] = { 0,1,0,-1 }; int R, C, T, Sy, Sx, Gy, Gx; string B[10]; int id(int y, int x) { return y * C + x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); cin >> R >> C >> T >> Sy >> Sx >> Gy >> Gx; rep(y, R)cin >> B[y]; auto A = vv(double, R*C, R*C, 0); rep(y, R)rep(x, C)if (B[y][x] != '#') { int cnt = 0; rep(i, 4) { int ny = y + DY[i], nx = x + DX[i]; if (B[ny][nx] == '.')cnt++; } rep(i, 4) { int ny = y + DY[i], nx = x + DX[i]; if (B[ny][nx] == '.') { A[id(y, x)][id(ny, nx)] = 1.0 / cnt; } } if (cnt == 0)A[id(y, x)][id(y, x)] = 1; } A = powMat(A, T); cout << A[id(Sy, Sx)][id(Gy, Gx)] << endl; }