import sys

input=sys.stdin.readline

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

si,sj,ti,tj=map(int,input().split())

si-=1

sj-=1

ti-=1

tj-=1

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

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

ans[si][sj]=0

from collections import deque

d=deque()

d.append((si,sj))

while d:

  x,y=d.popleft()

  if x==ti and y==tj:

    exit(print(ans[x][y]))

  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:

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

      xx=x+dx*i

      yy=y+dy*i

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

      if 0<=ans[xx][yy]<=ans[x][y]:break

      if ans[xx][yy]==-1:d.append((xx,yy))

      ans[xx][yy]=ans[x][y]+1

print(-1)

def main():

  import sys

  input=sys.stdin.readline

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

  sx,sy,tx,ty=map(int,input().split())

  b=[[-1]*(w+2)]

  for i in range(h):

    s=input()

    bb=[-1]

    for j in s:

      if j==".":bb.append(0)

      else:bb.append(-1)

    bb.append(-1)

    b.append(bb)

  b.append([-1]*(w+2))

  d=[]

  d.append((sx,sy))

  for ss in d:

    x,y=ss

    if x==tx and y==ty:

      exit(print(b[x][y]))

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

      if b[x+i][y]<=b[x][y] and b[x+i][y]!=0:break

      if b[x+i][y]==0:d.append((x+i,y))

      b[x+i][y]=b[x][y]+1

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

      if b[x-i][y]<=b[x][y] and b[x-i][y]!=0:break

      if b[x-i][y]==0:d.append((x-i,y))

      b[x-i][y]=b[x][y]+1

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

      if b[x][y+j]<=b[x][y] and b[x][y+j]!=0:break

      if b[x][y+j]==0:d.append((x,y+j))

      b[x][y+j]=b[x][y]+1

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

      if b[x][y-j]<=b[x][y] and b[x][y-j]!=0:break

      if b[x][y-j]==0:d.append((x,y-j))

      b[x][y-j]=b[x][y]+1

  print(-1)

if __name__ == "__main__":

  main()

import sys

input = sys.stdin.readline
h, w, k = map(int, input().split())
si, sj, ti, tj = map(int, input().split())
si -= 1
sj -= 1
ti -= 1
tj -= 1
b = [input() for _ in range(h)]
ans = [[-1] * w for _ in range(h)]
ans[si][sj] = 0
from collections import deque

d = deque()
d.append((si, sj))
while d:
    x, y = d.popleft()
    if x == ti and y == tj:
        exit(print(ans[x][y]))
    for dx, dy in [[1, 0], [-1, 0], [0, -1], [0, 1]]:
        for i in range(1, k + 1):
            xx = x + dx * i
            yy = y + dy * i
            if not (0 <= xx < h and 0 <= yy < w) or b[xx][yy] == "@":
                break
            if 0 <= ans[xx][yy] <= ans[x][y]:
                break
            if ans[xx][yy] == -1:
                d.append((xx, yy))
            ans[xx][yy] = ans[x][y] + 1
print(-1)

def main():
    import sys

    input = sys.stdin.readline
    h, w, k = map(int, input().split())
    sx, sy, tx, ty = map(int, input().split())
    b = [[-1] * (w + 2)]
    for i in range(h):
        s = input()
        bb = [-1]
        for j in s:
            if j == ".":
                bb.append(0)
            else:
                bb.append(-1)
        bb.append(-1)
        b.append(bb)
    b.append([-1] * (w + 2))
    d = []
    d.append((sx, sy))
    for ss in d:
        x, y = ss
        if x == tx and y == ty:
            exit(print(b[x][y]))
        for i in range(1, k + 1):
            if b[x + i][y] <= b[x][y] and b[x + i][y] != 0:
                break
            if b[x + i][y] == 0:
                d.append((x + i, y))
            b[x + i][y] = b[x][y] + 1
        for i in range(1, k + 1):
            if b[x - i][y] <= b[x][y] and b[x - i][y] != 0:
                break
            if b[x - i][y] == 0:
                d.append((x - i, y))
            b[x - i][y] = b[x][y] + 1
        for j in range(1, k + 1):
            if b[x][y + j] <= b[x][y] and b[x][y + j] != 0:
                break
            if b[x][y + j] == 0:
                d.append((x, y + j))
            b[x][y + j] = b[x][y] + 1
        for j in range(1, k + 1):
            if b[x][y - j] <= b[x][y] and b[x][y - j] != 0:
                break
            if b[x][y - j] == 0:
                d.append((x, y - j))
            b[x][y - j] = b[x][y] + 1
    print(-1)


if __name__ == "__main__":
    main()

-import sys +def main(): +    import sys -input = sys.stdin.readline -h, w, k = map(int, input().split()) -si, sj, ti, tj = map(int, input().split()) -si -= 1 -sj -= 1 -ti -= 1 -tj -= 1 -b = [input() for _ in range(h)] -ans = [[-1] * w for _ in range(h)] -ans[si][sj] = 0 -from collections import deque +    input = sys.stdin.readline +    h, w, k = map(int, input().split()) +    sx, sy, tx, ty = map(int, input().split()) +    b = [[-1] * (w + 2)] +    for i in range(h): +        s = input() +        bb = [-1] +        for j in s: +            if j == ".": +                bb.append(0) +            else: +                bb.append(-1) +        bb.append(-1) +        b.append(bb) +    b.append([-1] * (w + 2)) +    d = [] +    d.append((sx, sy)) +    for ss in d: +        x, y = ss +        if x == tx and y == ty: +            exit(print(b[x][y])) +        for i in range(1, k + 1): +            if b[x + i][y] <= b[x][y] and b[x + i][y] != 0: +                break +            if b[x + i][y] == 0: +                d.append((x + i, y)) +            b[x + i][y] = b[x][y] + 1 +        for i in range(1, k + 1): +            if b[x - i][y] <= b[x][y] and b[x - i][y] != 0: +                break +            if b[x - i][y] == 0: +                d.append((x - i, y)) +            b[x - i][y] = b[x][y] + 1 +        for j in range(1, k + 1): +            if b[x][y + j] <= b[x][y] and b[x][y + j] != 0: +                break +            if b[x][y + j] == 0: +                d.append((x, y + j)) +            b[x][y + j] = b[x][y] + 1 +        for j in range(1, k + 1): +            if b[x][y - j] <= b[x][y] and b[x][y - j] != 0: +                break +            if b[x][y - j] == 0: +                d.append((x, y - j)) +            b[x][y - j] = b[x][y] + 1 +    print(-1) -d = deque() -d.append((si, sj)) -while d: -    x, y = d.popleft() -    if x == ti and y == tj: -        exit(print(ans[x][y])) -    for dx, dy in [[1, 0], [-1, 0], [0, -1], [0, 1]]: -        for i in range(1, k + 1): -            xx = x + dx * i -            yy = y + dy * i -            if not (0 <= xx < h and 0 <= yy < w) or b[xx][yy] == "@": -                break -            if 0 <= ans[xx][yy] <= ans[x][y]: -                break -            if ans[xx][yy] == -1: -                d.append((xx, yy)) -            ans[xx][yy] = ans[x][y] + 1 -print(-1) + +if __name__ == "__main__": +    main()