#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int INF = int(1e9);

int n, m, k;
string s[1000000];
int sr, sc, tr, tc;
vector<int> d[1000000], used[1000000];
int qr[1000000], qc[1000000];
int ord[1000000];

bool cmplr(const int &lhs, const int &rhs) {
    return qc[lhs] < qc[rhs];
}

bool cmptb(const int &lhs, const int &rhs) {
    return qr[lhs] < qr[rhs];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m >> k;
    cin >> sr >> sc >> tr >> tc;
    --sr, --sc, --tr, --tc;
    forn(i, n) {
        cin >> s[i];
    }
    forn(i, n) {
        d[i].assign(m, INF);
        used[i].assign(m, INF);
    }
    d[sr][sc] = 0;
    qr[0] = sr;
    qc[0] = sc;
    int qb = 0, qe = 1;
    int val = 0, uind = 0;
    while (qb < qe) {
        int qmid = qb;
        while (qmid < qe && d[qr[qmid]][qc[qmid]] == val) {
            ++qmid;
        }
        int sz = 0;
        for (int qind = qb; qind < qmid; ++qind) {
            ord[sz++] = qind;
        }

        ++uind;
        sort(ord, ord + sz, cmplr);
        forn(oind, sz) {
            int qind = ord[oind];
            int r = qr[qind];
            int c = qc[qind];
            for (int j = c - 1; j >= max(0, c - k); --j) {
                if (s[r][j] == '@' || d[r][j] <= val || used[r][j] == uind) {
                    break;
                }
                if (d[r][j] == INF) {
                    d[r][j] = val + 1;
                    qr[qe] = r;
                    qc[qe++] = j;
                }
                used[r][j] = uind;
            }
        }
        ++uind;
        reverse(ord, ord + sz);
        forn(oind, sz) {
            int qind = ord[oind];
            int r = qr[qind];
            int c = qc[qind];
            for (int j = c + 1; j <= min(m - 1, c + k); ++j) {
                if (s[r][j] == '@' || d[r][j] <= val || used[r][j] == uind) {
                    break;
                }
                if (d[r][j] == INF) {
                    d[r][j] = val + 1;
                    qr[qe] = r;
                    qc[qe++] = j;
                }
                used[r][j] = uind;
            }
        }
        ++uind;
        sort(ord, ord + sz, cmptb);
        forn(oind, sz) {
            int qind = ord[oind];
            int r = qr[qind];
            int c = qc[qind];
            for (int i = r - 1; i >= max(0, r - k); --i) {
                if (s[i][c] == '@' || d[i][c] <= val || used[i][c] == uind) {
                    break;
                }
                if (d[i][c] == INF) {
                    d[i][c] = val + 1;
                    qr[qe] = i;
                    qc[qe++] = c;
                }
                used[i][c] = uind;
            }
        }
        ++uind;
        reverse(ord, ord + sz);
        forn(oind, sz) {
            int qind = ord[oind];
            int r = qr[qind];
            int c = qc[qind];
            for (int i = r + 1; i <= min(n - 1, r + k); ++i) {
                if (s[i][c] == '@' || d[i][c] <= val || used[i][c] == uind) {
                    break;
                }
                if (d[i][c] == INF) {
                    d[i][c] = val + 1;
                    qr[qe] = i;
                    qc[qe++] = c;
                }
                used[i][c] = uind;
            }
        }

        ++val;
        qb = qmid;
    }
    if (d[tr][tc] == INF) {
        d[tr][tc] = -1;
    }
    cout << d[tr][tc] << endl;
    return 0;
}


Measured memory_bytes: 96120