#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int N = 2e5;
vector <set <pair <int, int>>> activeX, activeY;
void deactivate (int x, int y) {
    activeX[x].erase (activeX[x].lower_bound ({y, 0}));
    activeY[y].erase (activeY[y].lower_bound ({x, 0}));
}

bool dst (int x1, int y1, int x2, int y2, int k) {
    return abs (x1 - x2) + abs (y1 - y2) <= k;
}

int main() {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    int n, m, k;
    cin >> n >> m >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    vector <vector <int>> dist (n + 1, vector <int> (m + 1, 0));
    activeX.resize (n + 1);
    activeY.resize (m + 1);
    for (int i = 1; i <= n; i++) {
        string str;
        cin >> str; str = " " + str;
        for (int j = 1; j <= m; j++) {
            activeX[i].insert ({j, str[j] == '.'});
            activeY[j].insert ({i, str[j] == '.'});
        }
    }

    queue <pair <int, int>> q;
    q.push ({x1, y1});
    dist[x1][y1] = 1;
    deactivate (x1, y1);
    while (q.size ()) {
        int x = q.front ().first;
        int y = q.front ().second;
        q.pop ();
        /// ---->
        bool ok;
        ok = true;
        while (ok) {
            if (activeX[x].upper_bound ({y, 0}) == activeX[x].end ()) {
                ok = false;
            }
            else {
                pair <int, bool> nxt = *activeX[x].upper_bound ({y, 0});
                if (nxt.second == false) {
                    ok = false;
                }
                else {
                    int nx = x;
                    int ny = nxt.first;
                    if (dst (x, y, nx, ny, k)) {
                        dist[nx][ny] = dist[x][y] + 1;
                        deactivate (nx, ny);
                        q.push ({nx, ny});
                    }
                    else
                        ok = false;
                }
            }
        }

        /// <-----
        ok = true;
        while (ok) {
            if (activeX[x].lower_bound ({y, 0}) == activeX[x].begin ()) {
                ok = false;
            }
            else {
                pair <int, bool> nxt = *prev (activeX[x].lower_bound ({y, 0}));
                if (nxt.second == false) {
                    ok = false;
                }
                else {
                    int nx = x;
                    int ny = nxt.first;
                    if (dst (x, y, nx, ny, k)) {
                        dist[nx][ny] = dist[x][y] + 1;
                        deactivate (nx, ny);
                        q.push ({nx, ny});
                    }
                    else
                        ok = false;
                }
            }
        }

        /// down

        ok = true;
        while (ok) {
            if (activeY[y].upper_bound ({x, 0}) == activeY[y].end ()) {
                ok = false;
            }
            else {
                pair <int, bool> nxt = *activeY[y].upper_bound ({x, 0});
                if (nxt.second == false) {
                    ok = false;
                }
                else {
                    int nx = nxt.first;
                    int ny = y;
                    if (dst (x, y, nx, ny, k)) {
                        dist[nx][ny] = dist[x][y] + 1;
                        deactivate (nx, ny);
                        q.push ({nx, ny});
                    }
                    else
                        ok = false;
                }
            }
        }

        /// up

        ok = true;
        while (ok) {
            if (activeY[y].lower_bound ({x, 0}) == activeY[y].begin ()) {
                ok = false;
            }
            else {
                pair <int, bool> nxt = *prev (activeY[y].lower_bound ({x, 0}));
                if (nxt.second == false) {
                    ok = false;
                }
                else {
                    int nx = nxt.first;
                    int ny = y;
                    if (dst (x, y, nx, ny, k)) {
                        dist[nx][ny] = dist[x][y] + 1;
                        deactivate (nx, ny);
                        q.push ({nx, ny});
                    }
                    else
                        ok = false;
                }
            }
        }

    }
    cout << dist[x2][y2] - 1 << "\n";
    return 0;
}


Measured memory_bytes: 152668