import sys

inf=1000002

sys.setrecursionlimit(inf)

from collections import deque

h,w,k=list(map(int,input().split()))

x1,y1,x2,y2=list(map(int,input().split()))

c=[eval(input()) for i in range(h)]

dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]

now=deque([[x1-1,y1-1]])

dp[x1-1][y1-1]=0

def bfs(d):

    global dp,now

    l=len(now)

    dp_sub=deque()

    cand=set()

    for i in range(l):

        x,y=now.popleft()

        for j in range(1,min(k+1,w-y)):

            if dp[x][y+j]==inf:

                dp_sub+=[[x,y+j,d]]

                cand.add((x,y+j))

            else:

                break

        for j in range(1,min(k+1,y+1)):

            if dp[x][y-j]==inf:

                dp_sub+=[[x,y-j,d]]

                cand.add((x,y-j))

            else:

                break

        for j in range(1,min(k+1,h-x)):

            if dp[x+j][y]==inf:

                dp_sub+=[[x+j,y,d]]

                cand.add((x+j,y))

            else:

                break

        for j in range(1,min(k+1,x+1)):

            if dp[x-j][y]==inf:

                dp_sub+=[[x-j,y,d]]

                cand.add((x-j,y))

            else:

                break

    while dp_sub!=deque([]):

        e=dp_sub.popleft()

        dp[e[0]][e[1]]=e[2]

    for i in cand:

        now+=[i]

    if l!=0:bfs(d+1)

bfs(1)

print((dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1))
h,w,k=map(int,input().split())

r,s,t,u=map(lambda x:int(x)-1,input().split())

b=[input()for _ in range(h)]

l=[[-1]*w for _ in range(h)]

l[r][s]=0

from collections import*

d=deque([(r,s)])

while d:

  x,y=d.popleft()

  if(x==t)&(y==u):exit(print(l[x][y]))

  for e,f in [[1,0],[-1,0],[0,-1],[0,1]]:

    for i in range(1,k+1):

      p,q=x+e*i,y+f*i

      if not(0<=p<h and 0<=q<w)or b[p][q]=="@":break

      if 0<=l[p][q]<=l[x][y]:break

      if l[p][q]==-1:d+=[(p,q)]

      l[p][q]=l[x][y]+1

print(-1)

import sys

inf = 1000002
sys.setrecursionlimit(inf)
from collections import deque

h, w, k = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
c = [eval(input()) for i in range(h)]
dp = [[inf if c[i][j] == "." else -1 for j in range(w)] for i in range(h)]
now = deque([[x1 - 1, y1 - 1]])
dp[x1 - 1][y1 - 1] = 0


def bfs(d):
    global dp, now
    l = len(now)
    dp_sub = deque()
    cand = set()
    for i in range(l):
        x, y = now.popleft()
        for j in range(1, min(k + 1, w - y)):
            if dp[x][y + j] == inf:
                dp_sub += [[x, y + j, d]]
                cand.add((x, y + j))
            else:
                break
        for j in range(1, min(k + 1, y + 1)):
            if dp[x][y - j] == inf:
                dp_sub += [[x, y - j, d]]
                cand.add((x, y - j))
            else:
                break
        for j in range(1, min(k + 1, h - x)):
            if dp[x + j][y] == inf:
                dp_sub += [[x + j, y, d]]
                cand.add((x + j, y))
            else:
                break
        for j in range(1, min(k + 1, x + 1)):
            if dp[x - j][y] == inf:
                dp_sub += [[x - j, y, d]]
                cand.add((x - j, y))
            else:
                break
    while dp_sub != deque([]):
        e = dp_sub.popleft()
        dp[e[0]][e[1]] = e[2]
    for i in cand:
        now += [i]
    if l != 0:
        bfs(d + 1)


bfs(1)
print((dp[x2 - 1][y2 - 1] if dp[x2 - 1][y2 - 1] != inf else -1))

h, w, k = map(int, input().split())
r, s, t, u = map(lambda x: int(x) - 1, input().split())
b = [input() for _ in range(h)]
l = [[-1] * w for _ in range(h)]
l[r][s] = 0
from collections import *

d = deque([(r, s)])
while d:
    x, y = d.popleft()
    if (x == t) & (y == u):
        exit(print(l[x][y]))
    for e, f in [[1, 0], [-1, 0], [0, -1], [0, 1]]:
        for i in range(1, k + 1):
            p, q = x + e * i, y + f * i
            if not (0 <= p < h and 0 <= q < w) or b[p][q] == "@":
                break
            if 0 <= l[p][q] <= l[x][y]:
                break
            if l[p][q] == -1:
                d += [(p, q)]
            l[p][q] = l[x][y] + 1
print(-1)

-import sys +h, w, k = map(int, input().split()) +r, s, t, u = map(lambda x: int(x) - 1, input().split()) +b = [input() for _ in range(h)] +l = [[-1] * w for _ in range(h)] +l[r][s] = 0 +from collections import * -inf = 1000002 -sys.setrecursionlimit(inf) -from collections import deque - -h, w, k = list(map(int, input().split())) -x1, y1, x2, y2 = list(map(int, input().split())) -c = [eval(input()) for i in range(h)] -dp = [[inf if c[i][j] == "." else -1 for j in range(w)] for i in range(h)] -now = deque([[x1 - 1, y1 - 1]]) -dp[x1 - 1][y1 - 1] = 0 - - -def bfs(d): -    global dp, now -    l = len(now) -    dp_sub = deque() -    cand = set() -    for i in range(l): -        x, y = now.popleft() -        for j in range(1, min(k + 1, w - y)): -            if dp[x][y + j] == inf: -                dp_sub += [[x, y + j, d]] -                cand.add((x, y + j)) -            else: +d = deque([(r, s)]) +while d: +    x, y = d.popleft() +    if (x == t) & (y == u): +        exit(print(l[x][y])) +    for e, f in [[1, 0], [-1, 0], [0, -1], [0, 1]]: +        for i in range(1, k + 1): +            p, q = x + e * i, y + f * i +            if not (0 <= p < h and 0 <= q < w) or b[p][q] == "@": -        for j in range(1, min(k + 1, y + 1)): -            if dp[x][y - j] == inf: -                dp_sub += [[x, y - j, d]] -                cand.add((x, y - j)) -            else: +            if 0 <= l[p][q] <= l[x][y]: -        for j in range(1, min(k + 1, h - x)): -            if dp[x + j][y] == inf: -                dp_sub += [[x + j, y, d]] -                cand.add((x + j, y)) -            else: -                break -        for j in range(1, min(k + 1, x + 1)): -            if dp[x - j][y] == inf: -                dp_sub += [[x - j, y, d]] -                cand.add((x - j, y)) -            else: -                break -    while dp_sub != deque([]): -        e = dp_sub.popleft() -        dp[e[0]][e[1]] = e[2] -    for i in cand: -        now += [i] -    if l != 0: -        bfs(d + 1) - - -bfs(1) -print((dp[x2 - 1][y2 - 1] if dp[x2 - 1][y2 - 1] != inf else -1)) +            if l[p][q] == -1: +                d += [(p, q)] +            l[p][q] = l[x][y] + 1 +print(-1)