def matmul(A,B): # A,B: 行列 res = [[0.0]*len(B[0]) for _ in range(len(A))] for i, resi in enumerate(res): for k, aik in enumerate(A[i]): for j,bkj in enumerate(B[k]): resi[j] += aik*bkj return res def matpow(A,p): #A^p mod M if p%2: return matmul(A, matpow(A,p-1)) elif p > 0: b = matpow(A,p//2) return matmul(b,b) else: return [[int(i==j)*1.0 for j in range(len(A))] for i in range(len(A))] h,w,t = map(int,input().split()) sx,sy = map(int,input().split()) gx,gy = map(int,input().split()) b = [input() for _ in range(h)] N = h*w A = [[0.0]*N for _ in range(N)] for i in range(1,h-1): for j in range(1,w-1): if b[i][j] == "#": continue v = i*w+j c = 0 for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]: if b[ni][nj] == ".": c += 1 if c==0: b[v][v] = 1.0 continue for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]: if b[ni][nj] == ".": A[v][ni*w+nj] = 1/c B = matpow(A,t) v = [0.0]*N v[sx*w+sy] = 1.0 v = matmul([v],B) print(v[0][gx*w+gy])