#include using namespace std; using ll = long long; const int dh[] = {1, -1, 0, 0}; const int dw[] = {0, 0, 1, -1}; double dp[2][10][10]; int cnt[10][10]; int main() { cin.tie(0); ios::sync_with_stdio(false); int r, c, t; cin >> r >> c >> t; int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx; vector s(r); for (int i = 0; i < r; i++) cin >> s[i]; for (int h = 0; h < r; h++) { for (int w = 0; w < c; w++) { for (int j = 0; j < 4; j++) { int nh = h + dh[j], nw = w + dw[j]; if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue; cnt[h][w] += (s[nh][nw] == '.'); } } } dp[0][sy][sx] = 1; for (int i = 0; i < max(t, 10000); i++) { for (int h = 0; h < r; h++) { for (int w = 0; w < c; w++) { for (int j = 0; j < 4; j++) { int nh = h + dh[j], nw = w + dw[j]; if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue; if (s[nh][nw] == '#') continue; dp[(i + 1) % 2][nh][nw] += dp[i % 2][h][w] / cnt[h][w]; } if (i + 1 < max(t, 10000)) dp[i % 2][h][w] = 0; } } } if (t <= 10000) cout << setprecision(10) << dp[t % 2][gy][gx] << endl; else { if ((t - 10000) % 2 == 1) cout << setprecision(10) << dp[1 - t % 2][gy][gx] << endl; else cout << setprecision(10) << dp[t % 2][gy][gx] << endl; } return 0; }