// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}




signed main(){
    int h, w, k;
    cin >> h >> w >> k;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    --sx, --sy, --ex, --ey;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)
        cin >> s[i];

    vector<vector<int>> dist(h, vector<int>(w, MOD));
    vector<vector<int>> kaku(h, vector<int>(w, false));
    dist[sx][sy] = 0;
    queue<pair<int,int>> que;

    vector<set<int>> vx(h);
    vector<set<int>> vy(w);
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j){
            if(i == sx && j == sy)
                continue;
            vx[i].emplace(j);
            vy[j].emplace(i);
        }

    vector<vector<int>> r_x(h, vector<int>(w, 0));
    vector<vector<int>> r_y(h, vector<int>(w, 0));
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j){
            r_x[i][j] = (s[i][j] == '@');
            r_y[i][j] = (s[i][j] == '@');
        }
    for(int i = 0; i < h; ++i){
        for(int j = 1; j < w; ++j)
            r_x[i][j] += r_x[i][j - 1];
    }
    for(int j = 0; j < w; ++j){
        for(int i = 1; i < h; ++i)
            r_y[i][j] += r_y[i - 1][j];
    }

    que.emplace(sx, sy);
    while(!que.empty()){
        int x, y;
        tie(x, y) = que.front();
        que.pop();
        if(kaku[x][y])
            continue;
        kaku[x][y] = true;

        for(auto iter = vx[x].lower_bound(y); iter != vx[x].end() && abs(*iter - y) <= k;){
            if(s[x][*iter] == '@' || r_x[x][y] != r_x[x][*iter])
                break;
            if(chmin(dist[x][*iter], dist[x][y] + 1)){
                que.emplace(x, *iter);
                vy[*iter].erase(x);
                iter = vx[x].erase(iter);
            }
            else
                ++iter;
        }
        for(auto iter = vx[x].lower_bound(y);;){
            if(iter == vx[x].begin())
                break;
            --iter;
            if(abs(*iter - y) > k)
                break;
            if(s[x][*iter] == '@' || r_x[x][y] != r_x[x][*iter])
                break;
            if(chmin(dist[x][*iter], dist[x][y] + 1)){
                que.emplace(x, *iter);
                vy[*iter].erase(x);
                iter = vx[x].erase(iter);
            }
        }

        for(auto iter = vy[y].lower_bound(x); iter != vy[y].end() && abs(*iter - x) <= k;){
            if(s[*iter][y] == '@' || r_y[x][y] != r_y[*iter][y])
                break;
            if(chmin(dist[*iter][y], dist[x][y] + 1)){
                que.emplace(*iter, y);
                vx[*iter].erase(y);
                iter = vy[y].erase(iter);
            }
            else
                ++iter;
        }
        for(auto iter = vy[y].lower_bound(x);;){
            if(iter == vy[y].begin())
                break;
            --iter;
            if(abs(*iter - x) > k)
                break;
            if(s[*iter][y] == '@' || r_y[x][y] != r_y[*iter][y])
                break;
            if(chmin(dist[*iter][y], dist[x][y] + 1)){
                que.emplace(*iter, y);
                vx[*iter].erase(y);
                iter = vy[y].erase(iter);
            }
        }

    }
    cout << (dist[ex][ey] == MOD ? -1 : dist[ex][ey]) << endl;

    return 0;
}


Measured memory_bytes: 164456