import numpy as np #A**n def mat_pow(A, n): size = len(A) res = np.eye(size, dtype=np.float) while n > 0: if n & 1 == 1: res = res @ A A = A @ A n = n>>1 return res import sys import io, os input = sys.stdin.readline def main(): r, c, t = map(int, input().split()) sy, sx = map(int, input().split()) gy, gx = map(int, input().split()) B = [] for i in range(r): temp = str(input().rstrip()) B.append(temp) B = ''.join(B) A = [[0]*(r*c) for i in range(r*c)] A = np.array(A, dtype=np.float) for y in range(r): for x in range(c): v = y*c+x if B[v] == '#': continue p = 0 cand = [] for dy, dx in (-1, 0), (1, 0), (0, 1), (0, -1): ny, nx = y+dy, x+dx nv = ny*c+nx if 0 <= ny < r and 0 <= nx < c and B[nv] != '#': p += 1 cand.append(nv) if p == 0: A[v][v] = 1 continue for nv in cand: A[nv][v] += 1/p #print(A) sv = sy*c+sx gv = gy*c+gx X = [0]*(r*c) X[sv] = 1 A = mat_pow(A, t) ans = 0 for v in range(v): ans += A[gv][v]*X[v] print(ans) if __name__ == '__main__': main()