/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 1000010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, k;
string s[MAXN];
int X1, Y1, X2, Y2;
vector<vector<int> > d, up, down, lef, rig;
vector<set<int> > row, col;
queue<II> q;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m >> k;
    cin >> X1 >> Y1 >> X2 >> Y2;
    FOR(i,0,n-1) cin >> s[i];
    X1--; Y1--; X2--; Y2--;

    row.resize(n);
    col.resize(m);

    FOR(i,0,n-1)
        FOR(j,0,m-1)
            if (s[i][j] == '.') {
                if (i == X1 && j == Y1) continue;
                row[i].insert(j);
                col[j].insert(i);
            }

    d.resize(n);
    FOR(i,0,n-1) d[i].resize(m);
    up.resize(n);
    FOR(i,0,n-1) up[i].resize(m);
    down.resize(n);
    FOR(i,0,n-1) down[i].resize(m);
    lef.resize(n);
    FOR(i,0,n-1) lef[i].resize(m);
    rig.resize(n);
    FOR(i,0,n-1) rig[i].resize(m);

    FOR(i,0,n-1)
        FOR(j,0,m-1) {
            if (s[i][j] == '@') lef[i][j] = j;
            else if (j == 0) lef[i][j] = -1;
            else lef[i][j] = lef[i][j-1];

            if (s[i][j] == '@') up[i][j] = i;
            else if (i == 0) up[i][j] = -1;
            else up[i][j] = up[i-1][j];
        }

    FORE(i,n-1,0)
        FORE(j,m-1,0) {
            if (s[i][j] == '@') rig[i][j] = j;
            else if (j == m-1) rig[i][j] = m;
            else rig[i][j] = rig[i][j+1];

            if (s[i][j] == '@') down[i][j] = i;
            else if (i == n-1) down[i][j] = n;
            else down[i][j] = down[i+1][j];
        }

    FOR(i,0,n-1) FOR(j,0,m-1) d[i][j] = 1000000000;

    d[X1][Y1] = 0;
    q.push(II(X1, Y1));
    while (SZ(q)) {
        II r = q.front(); q.pop();
        int u = r.FI;
        int v = r.SE;
        int leftBorder = max(v-k, lef[u][v]);
        int rightBorder = min(v+k, rig[u][v]);
        int upBorder = max(u-k, up[u][v]);
        int downBorder = min(u+k, down[u][v]);
        auto it = row[u].lower_bound(leftBorder);
        while (it != row[u].end()) {
            int j = *it;
            if (j > rightBorder) break;
            d[u][j] = d[u][v] + 1;
            row[u].erase(it);
            col[j].erase(col[j].lower_bound(u));
            q.push(II(u, j));
            it = row[u].lower_bound(leftBorder);
        }

        it = col[v].lower_bound(upBorder);
        while (it != col[v].end()) {
            int i = *it;
            if (i > downBorder) break;
            d[i][v] = d[u][v] + 1;
            col[v].erase(it);
            row[i].erase(row[i].lower_bound(v));
            q.push(II(i, v));
            it = col[v].lower_bound(upBorder);
        }
    }
    if (d[X2][Y2] == 1000000000) cout << -1;
    else cout << d[X2][Y2];
    return 0;
}


Measured memory_bytes: 195132