#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <iomanip>
#include <sys/time.h>
#include <random>
#include <cassert>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int size(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


/**
 *
 * @param s 始点
 * @param g グラフ
 * @return sから各頂点への距離
 */
vector<ll> dijkstra2(int s, Graph& g, ll INF=LONG_LONG_MAX / 3, int k=0){
    typedef pair<ll, int> Ptmp;  // firstは最短距離、secondは頂点の番号

    unsigned int n = g.size();
    priority_queue<Ptmp, vector<Ptmp>, greater<Ptmp>> que;
    vector<ll> d(n, INF);

    d[s] = 0;
    que.push(Ptmp(d[s], s));

    while(!que.empty()){
        Ptmp p = que.top();   que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(auto e: g[v]){
            ll dis;
            if((v - e.vertice) % 4 == 0){
                dis = d[v] + 1;
            }
            else{
                if(d[v] % k == 0){
                    dis = d[v];
                }
                else{
                    dis = d[v] / k * k + k;
                }
            }
            if(d[e.vertice] > dis){
                d[e.vertice] = dis;
                que.push(Ptmp(d[e.vertice], e.vertice));
            }
        }
    }

    return d;
}


int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    Graph g(h * w * 4);

    vector<string> c(h);
    for(int i = 0; i < h; i++){
        cin >> c[i];
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(c[i][j] == '@')  continue;

            int x = (i * w + j) * 4;
            if(i > 0 && c[i-1][j] == '.'){
                int y = ((i-1) * w + j) * 4;
                g.add_edge(x, y);
            }
            if(i < h-1 && c[i+1][j] == '.'){
                int y = ((i+1) * w + j) * 4;
                g.add_edge(x+1, y+1);
            }
            if(j > 0 && c[i][j-1] == '.'){
                int y = (i * w + (j-1)) * 4;
                g.add_edge(x + 2, y+2);
            }
            if(j < w-1 && c[i][j+1] == '.'){
                int y = (i * w + j + 1) * 4;
                g.add_edge(x + 3, y + 3);
            }

            for(int l = 0; l < 4; l++){
                for(int l2 = l+1; l2 < 4; l2++){
                    g.add_edge(x+l, x+l2);
                    g.add_edge(x+l2, x+l);
                }
            }
        }
    }

    int s = (x1 * w + y1) * 4, e = (x2 * w + y2) * 4;
    vector<ll> res = dijkstra2(s, g, LONG_LONG_MAX / 3, k);
    ll total = min(min(res[e], res[e+1]), min(res[e+2], res[e+3]));
    if(total == LONG_LONG_MAX / 3){
        cout << -1 << endl;
    }
    else{
        cout << (total+k-1) / k << endl;
    }

    return 0;
}


Measured memory_bytes: 440280