#include <bits/stdc++.h>
#define ll long long

using namespace std;
vector < char > a[1000100];
vector < int > dis[1000100];
set < int > X[1000100],Y[1000100];
set < int >::iterator it;

int n,m,k;

void BFS(int x1, int y1)
{

    dis[x1][y1] = 0;

    queue < pair < int, int > > Q;
    Q.push({x1, y1});
    while(!Q.empty())
    {
        pair < int, int > point = Q.front();
        Q.pop();
        it = X[point.first].upper_bound(point.second);
        vector < int > temp;
        if(it != X[point.first].end())
        {
            while(abs(point.second - *it) <= k && a[point.first][*it] != '@')
            {
                dis[point.first][*it] = min(dis[point.first][*it], dis[point.first][point.second] + 1);
                temp.push_back(*it);
                Q.push({point.first , *it});
                it++;
                if(it == X[point.first].end())  break;
            }
            for(auto q : temp)  X[point.first].erase(q);
            temp.clear();
        }
        it = X[point.first].lower_bound(point.second);
        if(it != X[point.first].begin())
        {
            it--;
            while(abs(point.second - *it) <= k && a[point.first][*it] != '@')
            {
                dis[point.first][*it] = min(dis[point.first][*it], dis[point.first][point.second] + 1);
                temp.push_back(*it);
                Q.push({point.first , *it});
                if(it == X[point.first].begin())  break;
                it--;
            }
            for(auto q : temp)  X[point.first].erase(q);
            temp.clear();
        }


        it = Y[point.second].upper_bound(point.first);
        if(it != Y[point.second].end())
        {
            while(abs(point.first - *it) <= k && a[*it][point.second] != '@')
            {
                dis[*it][point.second] = min(dis[*it][point.second], dis[point.first][point.second] + 1);
                temp.push_back(*it);
                Q.push({*it , point.second});
                it++;
                if(it == Y[point.second].end())  break;
            }
            for(auto q : temp)  Y[point.second].erase(q);
            temp.clear();
        }
        it = Y[point.second].lower_bound(point.first);
        if(it != Y[point.second].begin())
        {
            it--;
            while(abs(point.first - *it) <= k && a[*it][point.second] != '@')
            {
                dis[*it][point.second] = min(dis[*it][point.second], dis[point.first][point.second] + 1);
                temp.push_back(*it);
                Q.push({*it , point.second});
                if(it == Y[point.second].begin())  break;
                it--;
            }
            for(auto q : temp)  Y[point.second].erase(q);
            temp.clear();
        }
    }
}

int main()
{
    cin >> n >> m >> k;
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    x2--;
    y2--;
    for(int i = 0; i<n; i++)  a[i].resize(m), dis[i].resize(m);
    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<m; j++)
        {
            cin >> a[i][j];
            dis[i][j] = 1e9;
            X[i].insert(j);
        }
    }
    for(int j = 0; j<m; j++)
    {
        for(int i = 0; i<n; i++)
        {
            Y[j].insert(i);
        }
    }
    BFS(x1, y1);
    cout << (dis[x2][y2] == 1e9 ? -1 : dis[x2][y2]);
    return 0;
}


Measured memory_bytes: 242940