#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int H,W,K; cin >> H >> W >> K;
    int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
    --sx; --sy; --tx; --ty;
    vector<set<int>> R(H),C(W),AR(H),AC(W);
    vector<string> S(H);
    rep(i,H) cin >> S[i];
    rep(i,H) rep(j,W) {
        if (i==sx and j==sy) continue;
        if (S[i][j]=='.') {
            R[i].emplace(j);
            C[j].emplace(i);
        } else {
            AR[i].emplace(j);
            AC[j].emplace(i);
        }
    }

    queue<pii> que;
    que.emplace(sx,sy);
    vector<vector<int>> dist(H, vector<int>(W,-1));
    dist[sx][sy] = 0;
    while (!que.empty()) {
        auto[x,y] = que.front(); que.pop();
        //cout << x << " " << y << endl;
        auto it1 = AR[x].lower_bound(y);
        int ry = it1 == AR[x].end() ? W : *it1;
        chmin(ry,y+K+1);
        auto it2 = R[x].upper_bound(y);
        while (it2 != R[x].end() and *it2 < ry) {
            dist[x][*it2] = dist[x][y]+1;
            que.emplace(x,*it2);
            C[*it2].erase(x);
            it2 = R[x].erase(it2);
        }
        //cout << "R" << endl;
        auto it3 = AR[x].lower_bound(y);
        int ly = it3 == AR[x].begin() ? -1 : *prev(it3);
        chmax(ly,y-K-1);
        auto it4 = R[x].lower_bound(y);
        while (it4 != R[x].begin() and *prev(it4) > ly) {
            --it4;
            dist[x][*it4] = dist[x][y]+1;
            que.emplace(x,*it4);
            C[*it4].erase(x);
            it4 = R[x].erase(it4);
        }
        //cout << "L" << endl;
        auto it5 = AC[y].lower_bound(x);
        int rx = it5 == AC[y].end() ? H : *it5;
        chmin(rx,x+K+1);
        auto it6 = C[y].upper_bound(x);
        while (it6 != C[y].end() and *it6 < rx) {
            dist[*it6][y] = dist[x][y]+1;
            que.emplace(*it6,y);
            R[*it6].erase(y);
            it6 = C[y].erase(it6);
        }
        //cout << "U" << endl;
        auto it7 = AC[y].lower_bound(x);
        int lx = it7 == AC[y].begin() ? -1 : *prev(it7);
        chmax(lx,x-K-1);
        auto it8 = C[y].lower_bound(x);
        while (it8 != C[y].begin() and *prev(it8) > lx) {
            --it8;
            dist[*it8][y] = dist[x][y]+1;
            que.emplace(*it8,y);
            R[*it8].erase(y);
            it8 = C[y].erase(it8);
        }
        //cout << "D" << endl;
    }
    // rep(i,H) {
    //     rep(j,W) cout << dist[i][j] << " ";
    //     cout << ln;
    // }
    cout << dist[tx][ty] << ln;
}

Measured memory_bytes: 199660