#include using namespace std; template using vec = vector; template using mat = vec>; template mat mat_mul(mat a, mat b) { mat c(a.size(), vec(b[0].size())); for (int i = 0; i < a.size(); ++i) { for (int k = 0; k < b.size(); ++k) { for (int j = 0; j < b[0].size(); ++j) { c[i][j] += a[i][k] * b[k][j]; } } } return c; } template mat mat_pow(mat a, int p) { mat r = a; for (int i = p - 1; i; i >>= 1) { if (i & 1) r = mat_mul(r, a); a = mat_mul(a, a); } return r; } signed main() { ios::sync_with_stdio(false); int R, C, T; cin >> R >> C >> T; int Sx, Sy, Gx, Gy; cin >> Sx >> Sy >> Gx >> Gy; vector G(R); for (int i = 0; i < R; ++i) { cin >> G[i]; } mat f(R * C, vec(R * C)); for (int i = 0; i < R; ++i) { for (int j = 0; j < C; ++j) { if (G[i][j] == '#') continue; int d = 0; for (int di = 0; di < 4; ++di) { static const int dx[] = {0, 1, 0, -1}; static const int dy[] = {1, 0, -1, 0}; int x = i + dx[di]; int y = j + dy[di]; if (x < 0 || x == R || y < 0 || y == C) continue; if (G[x][y] == '#') continue; ++d; } if (d) { for (int di = 0; di < 4; ++di) { static const int dx[] = {0, 1, 0, -1}; static const int dy[] = {1, 0, -1, 0}; int x = i + dx[di]; int y = j + dy[di]; if (x < 0 || x == R || y < 0 || y == C) continue; if (G[x][y] == '#') continue; f[i * C + j][x * C + y] = 1.0 / d; } } else { f[i * C + j][i * C + j] = 1.0; } } } mat y = mat_pow(f, T); cout << fixed << setprecision(9) << y[Sx * C + Sy][Gx * C + Gy] << endl; return 0; }