#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np # %% R, C, T = map(int, readline().split()) Sy, Sx = map(int, readline().split()) Gy, Gx = map(int, readline().split()) B = ''.join(read().decode().split()) # %% N = R * C graph = [[] for _ in range(N)] mat = np.zeros((N,N)) for i in range(N): if B[i] == '#': continue deg = 0 for dx in [1, -1, -C, C]: if B[i + dx] == '.': deg += 1 if deg == 0: mat[i, i] = 1.0 else: p = 1 / deg for dx in [1, -1, -C, C]: if B[i + dx] == '.': mat[i, i + dx] = 1 / deg # %% A = np.linalg.matrix_power(mat, T) S = Sy * C + Sx G = Gy * C + Gx print(A[S,G])