#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } using Num = double; struct Matrix { vector > v, w; Matrix() {} Matrix(int n, int m) : v(n, vector(m)) { } inline int height() const { return (int)v.size(); } inline int width() const { return (int)v[0].size(); } inline Num& at(int i, int j) { return v[i][j]; } inline const Num& at(int i, int j) const { return v[i][j]; } static Matrix identity(int n) { Matrix A(n, n); rep(i, n) A.at(i, i) = 1; return A; } inline static Matrix identity(const Matrix& A) { return identity(A.height()); } Matrix& operator*=(const Matrix& B) { int n = height(), m = B.width(), p = B.height(); assert(p == width()); w.assign(n, vector(m, 0)); rep(i, n) rep(j, m) { Num x = 0; rep(k, p) x += at(i, k) * B.at(k, j); w[i][j] = x; } v.swap(w); return *this; } }; Matrix operator^(const Matrix& t, ll k) { Matrix A = t, B = Matrix::identity(t); while (k) { if (k & 1) B *= A; A *= A; k >>= 1; } return B; } int main() { int H; int W; int T; while (~scanf("%d%d%d", &H, &W, &T)) { int sy; int sx; scanf("%d%d", &sy, &sx); int gy; int gx; scanf("%d%d", &gy, &gx); vector maze(H); rep(i, H) { char buf[101]; scanf("%s", buf); maze[i] = buf; } Matrix A(H * W, H * W); rep(i, H) rep(j, W) if(maze[i][j] != '#') { static const int dy[4] = { 0, 1, 0, -1 }, dx[4] = { 1, 0, -1, 0 }; vector next; for (int d = 0; d < 4; ++ d) { int yy = i + dy[d], xx = j + dx[d]; if (yy < 0 || yy >= H || xx < 0 || xx >= W) continue; if (maze[yy][xx] == '#') continue; next.push_back(yy * W + xx); } int cur = i * W + j; if (next.empty()) { A.at(cur, cur) += 1; } else { double p = 1. / next.size(); for (int t : next) A.at(cur, t) += p; } } A = A ^ T; auto ans = A.at(sy * W + sx, gy * W + gx); printf("%.10f\n", ans); } return 0; }