#include <bits/stdc++.h>
using namespace std;

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

const int OO=1e9+9;
int h, w, k;
pi s, t;
vector< vector<bool> > vis;
vector< vector<char> > grid;
vector< set<int> > rows, cols;
vector< vector<int> > dist, lst[4]; // 0 - left
                                    // 1 - top
                                    // 2 - right
                                    // 3 - down

void BFS() {
    queue<pi> q;
    q.push(s);
    vis[s.F][s.S]=1;
    dist[s.F][s.S]=0;
    rows[s.F].erase(s.S);
    cols[s.S].erase(s.F);

    while (!q.empty()) {
        pi cur=q.front();
        q.pop();

        int currentRow=cur.F,
            currentCol=cur.S;
        while (!rows[currentRow].empty()) {
            bool edit=0;

            auto nxt=rows[currentRow].upper_bound(currentCol);

            if (nxt!=rows[currentRow].end() && *nxt<lst[2][currentRow][currentCol] && *nxt-currentCol<=k && !vis[currentRow][*nxt]) {
                edit=1;
                vis[currentRow][*nxt]=1;
                dist[currentRow][*nxt]=dist[currentRow][currentCol]+1;
                q.push({currentRow, *nxt});
                rows[currentRow].erase(*nxt);
                cols[*nxt].erase(currentRow);
            }

            if (!rows[currentRow].empty()) {
                auto prv=rows[currentRow].upper_bound(currentCol);

                if (prv!=rows[currentRow].begin()) {
                    --prv;

                    if (*prv>lst[0][currentRow][currentCol] && currentCol-(*prv)<=k && !vis[currentRow][*prv]) {
                        edit=1;
                        vis[currentRow][*prv]=1;
                        dist[currentRow][*prv]=dist[currentRow][currentCol]+1;
                        q.push({currentRow, *prv});
                        rows[currentRow].erase(*prv);
                        cols[*prv].erase(currentRow);
                    }
                }
            }

            if (!edit) {
                break;
            }
        }

        while (!cols[currentCol].empty()) {
            bool edit=0;

            auto nxt=cols[currentCol].upper_bound(currentRow);
            if (nxt!=cols[currentCol].end() && *nxt<lst[3][currentRow][currentCol] && *nxt-currentRow<=k && !vis[*nxt][currentCol]) {
                edit=1;
                vis[*nxt][currentCol]=1;
                dist[*nxt][currentCol]=dist[currentRow][currentCol]+1;
                q.push({*nxt, currentCol});
                cols[currentCol].erase(*nxt);
                rows[*nxt].erase(currentCol);
            }

            if (!cols[currentCol].empty()) {
                auto prv=cols[currentCol].upper_bound(currentRow);
                if (prv!=cols[currentCol].begin()) {
                    --prv;

                    if (*prv>lst[1][currentRow][currentCol] && currentRow-(*prv)<=k && !vis[*prv][currentCol]) {
                        edit=1;
                        vis[*prv][currentCol]=1;
                        dist[*prv][currentCol]=dist[currentRow][currentCol]+1;
                        q.push({*prv, currentCol});
                        cols[currentCol].erase(*prv);
                        rows[*prv].erase(currentCol);
                    }
                }
            }

            if (!edit) {
                break;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> w >> k;

    cin >> s.F >> s.S
        >> t.F >> t.S;

    vis=vector< vector<bool> >(h+1, vector<bool>(w+1));
    grid=vector< vector<char> >(h+1, vector<char>(w+1));
    rows=vector< set<int> > (h+1);
    cols=vector< set<int> >(w+1);
    dist=vector< vector<int> >(h+1, vector<int>(w+1, OO));

    for (int i=0; i<4; ++i) {
        lst[i]=vector< vector<int> >(h+1, vector<int>(w+1));
    }

    for (int i=1; i<=h; ++i) {
        for (int j=1; j<=w; ++j) {
            cin >> grid[i][j];

            rows[i].insert(j);
            cols[j].insert(i);
        }
    }

    // set left
    for (int i=1; i<=h; ++i) {
        for (int j=1; j<=w; ++j) {
            if (j==1)                  lst[0][i][j]=0;

            if (grid[i][j]=='@')       lst[0][i][j]=j;
            else if (j!=1)             lst[0][i][j]=lst[0][i][j-1];
        }
    }

    // set right
    for (int i=1; i<=h; ++i) {
        for (int j=w; j>=1; --j) {
            if (j==w)                  lst[2][i][j]=w+1;

            if (grid[i][j]=='@')       lst[2][i][j]=j;
            else if (j!=w)             lst[2][i][j]=lst[2][i][j+1];
        }
    }

    // set top
    for (int j=1; j<=w; ++j) {
        for (int i=1; i<=h; ++i) {
            if (i==1)                  lst[1][i][j]=0;

            if (grid[i][j]=='@')       lst[1][i][j]=i;
            else if (i!=1)             lst[1][i][j]=lst[1][i-1][j];
        }
    }

    // set downs
    for (int j=1; j<=w; ++j) {
        for (int i=h; i>=1; --i) {
            if (i==h)                  lst[3][i][j]=h+1;

            if (grid[i][j]=='@')       lst[3][i][j]=i;
            else if (i!=h)             lst[3][i][j]=lst[3][i+1][j];
        }
    }

    BFS();

    cout << (dist[t.F][t.S]==OO ? -1 : dist[t.F][t.S]);

    return 0;
}


Measured memory_bytes: 185248