#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}

template<typename T>
struct Dijkstra{
    const T inf=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n;
    vector<vector<pair<int,T>>> G;
    vector<T> d;
    Dijkstra(int n):n(n),G(n),d(n){}
    void add_edge(int u,int v,T w){
        G[u].emplace_back(v,w);
    }
    vector<T> build(int s){
        fill(d.begin(),d.end(),inf);
        d[s]=0;
        priority_queue<P,vector<P>,greater<P>> pq;
        pq.emplace(d[s],s);
        while(!pq.empty()){
            P p=pq.top(); pq.pop();
            int v=p.second;
            if (d[v]<p.first) continue;
            for (auto &e:G[v]){
                int u=e.first; T c=e.second;
                if (d[v]+c<d[u]){
                    d[u]=d[v]+c;
                    pq.emplace(d[u],u);
                }
            }
        }
        return d;
    }
};

using P=pair<pair<int,int>,int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,K; cin >> H >> W >> K;
    vector<int> s(2),t(2);
    for (int i=0;i<2;++i) cin >> s[i],--s[i];
    for (int i=0;i<2;++i) cin >> t[i],--t[i];
    vector<string> S(H);
    for (int i=0;i<H;++i) cin >> S[i];
    int N=H*W*4;
    struct edge{
        int u,c1,c2;
        edge(int u,int c1,int c2):u(u),c1(c1),c2(c2){}
    };
    vector<vector<edge>> G(N);
    for (int i=0;i<N;++i){
        int I=i;
        int id=I%4; (I-=id)/=4;
        int w=I%W; (I-=w)/=W;
        int h=I;
        if (S[h][w]=='@') continue;
        for (int j=0;j<4;++j){
            if (j%2!=id%2){
                G[i].emplace_back((h*W+w)*4+j,1,0);
            }
        }
        if (id==0&&h<H-1&&S[h+1][w]!='@') G[i].emplace_back(((h+1)*W+w)*4+id,0,1);
        if (id==1&&w<W-1&&S[h][w+1]!='@') G[i].emplace_back((h*W+(w+1))*4+id,0,1);
        if (id==2&&h>0&&S[h-1][w]!='@') G[i].emplace_back(((h-1)*W+w)*4+id,0,1);
        if (id==3&&w>0&&S[h][w-1]!='@') G[i].emplace_back((h*W+(w-1))*4+id,0,1);
    }
    vector<pair<int,int>> d(N,{INF,INF});
    priority_queue<P,vector<P>,greater<P>> pq;
    for (int i=0;i<4;++i){
        d[(s[0]*W+s[1])*4+i]={1,0};
        pq.push({{1,0},(s[0]*W+s[1])*4+i});
    }
    while(!pq.empty()){
        auto p=pq.top(); pq.pop();
        int v=p.second;
        auto cost=p.first;
        // debug(v,cost);
        if (d[v]<cost) continue;
        for (auto e:G[v]){
            int u=e.u;
            pair<int,int> ncost;
            if (e.c1==1) ncost={cost.first+1,0};
            else {
                ncost={cost.first,cost.second+e.c2};
            }
            if (ncost.second==K+1) ncost.first+=1,ncost.second=1;
            if (ncost<d[u]){
                d[u]=ncost;
                pq.push({d[u],u});
            }
        }
    }
    int ans=INF;
    for (int i=0;i<H;++i){
        for (int j=0;j<W;++j){
            pair<int,int> p={INF,INF};
            // cout << i << ' ' << j << '#';
            for (int k=0;k<4;++k){
                // cout << d[(i*W+j)*4+k] << (k+1==4?'\n':' ');
                chmin(p,d[(i*W+j)*4+k]);
            }
            //cout << p << (j+1==W?'\n':' ');
        }
    }
    for (int i=0;i<4;++i){
        ans=min(ans,d[(t[0]*W+t[1])*4+i].first);
    }
    cout << (ans==INF?-1:ans) << '\n';
}

Measured memory_bytes: 315784