#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, k; cin >> h >> w >> k;
    ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;

    V< V<char> > c(h, V<char>(w, '.'));
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }

    V< set<int> > rowidx(h), colidx(w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) rowidx[i].insert(j);
    }
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) colidx[i].insert(j);
    }

    V< V<int> > dist(h, V<int>(w, INF));
    dist[x1][y1] = 0;
    queue< P<int, int> > que;
    que.push( make_pair(x1, y1) );
    while (!que.empty()) {
        P<int, int> q = que.front();
        que.pop();
        ll curx = q.first, cury = q.second;
        // to right
        {
            ll tmpy = cury;
            while (true) {
                auto it = rowidx[curx].upper_bound(tmpy);
                if (it == rowidx[curx].end()) break;
                ll nxty = *it;
                if (c[curx][nxty] == '@' || nxty > cury + k) break;
                dist[curx][nxty] = dist[curx][cury] + 1;
                que.push( make_pair(curx, nxty) );
                rowidx[curx].erase(nxty);
                colidx[nxty].erase(curx);
                tmpy = nxty;
            }
        }
        // to left
        {
            ll tmpy = cury;
            while (true) {
                auto it = rowidx[curx].lower_bound(tmpy);
                if (it == rowidx[curx].begin()) break;
                ll nxty = *prev(it);
                if (c[curx][nxty] == '@' || nxty < cury - k) break;
                dist[curx][nxty] = dist[curx][cury] + 1;
                que.push( make_pair(curx, nxty) );
                rowidx[curx].erase(nxty);
                colidx[nxty].erase(curx);
                tmpy = nxty;
            }
        }
        // to top
        {
            ll tmpx = curx;
            while (true) {
                auto it = colidx[cury].lower_bound(tmpx);
                if (it == colidx[cury].begin()) break;
                ll nxtx = *prev(it);
                if (c[nxtx][cury] == '@' || nxtx < curx - k) break;
                dist[nxtx][cury] = dist[curx][cury] + 1;
                que.push( make_pair(nxtx, cury) );
                rowidx[nxtx].erase(cury);
                colidx[cury].erase(nxtx);
                tmpx = nxtx;
            }
        }
        // to bottom
        {
            ll tmpx = curx;
            while (true) {
                auto it = colidx[cury].upper_bound(tmpx);
                if (it == colidx[cury].end()) break;
                ll nxtx = *it;
                if (c[nxtx][cury] == '@' || nxtx > curx + k) break;
                dist[nxtx][cury] = dist[curx][cury] + 1;
                que.push( make_pair(nxtx, cury) );
                rowidx[nxtx].erase(cury);
                colidx[cury].erase(nxtx);
                tmpx = nxtx;
            }
        }
    }

    if (dist[x2][y2] == INF) cout << -1 << '\n';
    else cout << dist[x2][y2] << '\n';
    return 0;
}


Measured memory_bytes: 152676