# A*B def mat_mul(A, B): C = [[0]*len(B[0]) for i in range(len(A))] for i in range(len(A)): for k in range(len(B)): for j in range(len(B[0])): C[i][j] = (C[i][j] + A[i][k]*B[k][j]) return C #A**n def mat_pow(A, n): B = [[0]*len(A) for i in range(len(A))] for i in range(len(A)): B[i][i] = 1 while n > 0: if n & 1 == 1: B = mat_mul(A, B) A = mat_mul(A, A) n = n>>1 return B import sys import io, os input = sys.stdin.readline 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)] 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 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)