from collections import deque





H, W, K = list(map(int, input().split()))

x1, y1, x2, y2 = [int(x) - 1 for x in input().split()]

grid = [eval(input()) for _ in range(H)]



INF = float('inf')

path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)]



q = deque()

for d in range(4):

    path[x1][y1][d] = (1, 0)

    q.append((x1, y1, d, 1, 0))



D = [(-1, 0), (0, 1), (1, 0), (0, -1)]

while q:

    x, y, d, s, k = q.popleft()

    if k == K:

        for nd in range(4):

            if nd == d:

                dx, dy = D[nd]

                nk = 1

            else:

                dx, dy = 0, 0

                nk = 0

            nx = x + dx; ny = y + dy

            ns = s + 1

            if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk):

                path[nx][ny][nd] = (ns, nk)

                q.append((nx, ny, nd, ns, nk))

    else:

        for nd in range(4):

            if nd == d:

                dx, dy = D[nd]

                nk = k + 1

            else:

                dx, dy = 0, 0

                nk = 0

            nx = x + dx; ny = y + dy

            ns = s + (d != nd)

            if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk):

                path[nx][ny][nd] = (ns, nk)

                if ns == s:

                    q.appendleft((nx, ny, nd, ns, nk))

                else:

                    q.append((nx, ny, nd, ns, nk))



ans = INF

for d in range(4):

    ans = min(ans, path[x2][y2][d][0])

ans = -1 if ans == INF else ans

print(ans)

from collections import deque





H, W, K = list(map(int, input().split()))

x1, y1, x2, y2 = [int(x) - 1 for x in input().split()]

grid = [eval(input()) for _ in range(H)]



INF = float('inf')

path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)]



q = deque()

for d in range(4):

    path[x1][y1][d] = (1, 0)

    q.append((x1, y1, d, 1, 0))



D = [(-1, 0), (0, 1), (1, 0), (0, -1)]

while q:

    x, y, d, s, k = q.popleft()

    for nd in range(4):

        if nd == d:

            dx, dy = D[nd]

            nk = 1 if k == K else k + 1

            ns = s + 1 if k == K else s

        else:

            dx, dy = 0, 0

            nk = 0

            ns = s + 1

        nx = x + dx; ny = y + dy

        if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk):

            path[nx][ny][nd] = (ns, nk)

            if ns == s:

                q.appendleft((nx, ny, nd, ns, nk))

            else:

                q.append((nx, ny, nd, ns, nk))



ans = INF

for d in range(4):

    ans = min(ans, path[x2][y2][d][0])

ans = -1 if ans == INF else ans

print(ans)

from collections import deque

H, W, K = list(map(int, input().split()))
x1, y1, x2, y2 = [int(x) - 1 for x in input().split()]
grid = [eval(input()) for _ in range(H)]
INF = float("inf")
path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)]
q = deque()
for d in range(4):
    path[x1][y1][d] = (1, 0)
    q.append((x1, y1, d, 1, 0))
D = [(-1, 0), (0, 1), (1, 0), (0, -1)]
while q:
    x, y, d, s, k = q.popleft()
    if k == K:
        for nd in range(4):
            if nd == d:
                dx, dy = D[nd]
                nk = 1
            else:
                dx, dy = 0, 0
                nk = 0
            nx = x + dx
            ny = y + dy
            ns = s + 1
            if (
                0 <= nx < H
                and 0 <= ny < W
                and grid[nx][ny] == "."
                and path[nx][ny][nd] > (ns, nk)
            ):
                path[nx][ny][nd] = (ns, nk)
                q.append((nx, ny, nd, ns, nk))
    else:
        for nd in range(4):
            if nd == d:
                dx, dy = D[nd]
                nk = k + 1
            else:
                dx, dy = 0, 0
                nk = 0
            nx = x + dx
            ny = y + dy
            ns = s + (d != nd)
            if (
                0 <= nx < H
                and 0 <= ny < W
                and grid[nx][ny] == "."
                and path[nx][ny][nd] > (ns, nk)
            ):
                path[nx][ny][nd] = (ns, nk)
                if ns == s:
                    q.appendleft((nx, ny, nd, ns, nk))
                else:
                    q.append((nx, ny, nd, ns, nk))
ans = INF
for d in range(4):
    ans = min(ans, path[x2][y2][d][0])
ans = -1 if ans == INF else ans
print(ans)

from collections import deque

H, W, K = list(map(int, input().split()))
x1, y1, x2, y2 = [int(x) - 1 for x in input().split()]
grid = [eval(input()) for _ in range(H)]
INF = float("inf")
path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)]
q = deque()
for d in range(4):
    path[x1][y1][d] = (1, 0)
    q.append((x1, y1, d, 1, 0))
D = [(-1, 0), (0, 1), (1, 0), (0, -1)]
while q:
    x, y, d, s, k = q.popleft()
    for nd in range(4):
        if nd == d:
            dx, dy = D[nd]
            nk = 1 if k == K else k + 1
            ns = s + 1 if k == K else s
        else:
            dx, dy = 0, 0
            nk = 0
            ns = s + 1
        nx = x + dx
        ny = y + dy
        if (
            0 <= nx < H
            and 0 <= ny < W
            and grid[nx][ny] == "."
            and path[nx][ny][nd] > (ns, nk)
        ):
            path[nx][ny][nd] = (ns, nk)
            if ns == s:
                q.appendleft((nx, ny, nd, ns, nk))
            else:
                q.append((nx, ny, nd, ns, nk))
ans = INF
for d in range(4):
    ans = min(ans, path[x2][y2][d][0])
ans = -1 if ans == INF else ans
print(ans)

-    if k == K: -        for nd in range(4): -            if nd == d: -                dx, dy = D[nd] -                nk = 1 +    for nd in range(4): +        if nd == d: +            dx, dy = D[nd] +            nk = 1 if k == K else k + 1 +            ns = s + 1 if k == K else s +        else: +            dx, dy = 0, 0 +            nk = 0 +            ns = s + 1 +        nx = x + dx +        ny = y + dy +        if ( +            0 <= nx < H +            and 0 <= ny < W +            and grid[nx][ny] == "." +            and path[nx][ny][nd] > (ns, nk) +        ): +            path[nx][ny][nd] = (ns, nk) +            if ns == s: +                q.appendleft((nx, ny, nd, ns, nk)) -                dx, dy = 0, 0 -                nk = 0 -            nx = x + dx -            ny = y + dy -            ns = s + 1 -            if ( -                0 <= nx < H -                and 0 <= ny < W -                and grid[nx][ny] == "." -                and path[nx][ny][nd] > (ns, nk) -            ): -                path[nx][ny][nd] = (ns, nk) -    else: -        for nd in range(4): -            if nd == d: -                dx, dy = D[nd] -                nk = k + 1 -            else: -                dx, dy = 0, 0 -                nk = 0 -            nx = x + dx -            ny = y + dy -            ns = s + (d != nd) -            if ( -                0 <= nx < H -                and 0 <= ny < W -                and grid[nx][ny] == "." -                and path[nx][ny][nd] > (ns, nk) -            ): -                path[nx][ny][nd] = (ns, nk) -                if ns == s: -                    q.appendleft((nx, ny, nd, ns, nk)) -                else: -                    q.append((nx, ny, nd, ns, nk))