#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=1000005;
const ll INF=1LL<<60;
ll H,W,K;
ll dis[MAX];
set<ll> SE[MAX][2],out[MAX][2];

void BFS(ll s){
    queue<ll> Q;
    dis[s]=0;
    Q.push(s);
    SE[s/W][0].erase(s);
    SE[s%W][1].erase(s);
    
    while(!Q.empty()){
        ll u=Q.front();Q.pop();
        //cout<<u<<endl;
        ll h=u/W,w=u%W;
        
        auto it=SE[h][0].lower_bound(u),can=out[h][0].lower_bound(u);
        ll border=min(u+K,*can);
        
        while(*it<=border){
            ll a=*it;
            if(a<0||a>=H*W) break;
            //cout<<a<<endl;
            if(chmin(dis[a],dis[u]+1)){
                it++;
                
                Q.push(a);
                SE[h][0].erase(a);
                SE[a%W][1].erase(a);
                
                //cout<<*it<<endl;
            }else break;
        }
        
        it=SE[h][0].lower_bound(u);
        can=out[h][0].lower_bound(u);
        it--;
        can--;
        border=max(u-K,*can);
        
        while(*it>=border){
            ll a=*it;
            if(a<0||a>=H*W) break;
            if(chmin(dis[a],dis[u]+1)){
                it--;
                
                Q.push(a);
                SE[h][0].erase(a);
                SE[a%W][1].erase(a);
                //it--;
                
                //cout<<*it<<endl;
            }else break;
        }
        
        it=SE[w][1].lower_bound(u);can=out[w][1].lower_bound(u);
        border=min(u+W*K,*can);
        
        while(*it<=border){
            ll a=*it;
            if(a<0||a>=H*W) break;
            if(chmin(dis[a],dis[u]+1)){
                it++;
                
                Q.push(a);
                SE[w][1].erase(a);
                SE[a/W][0].erase(a);
                //it++;
                
                //cout<<*it<<endl;
            }else break;
        }
        
        it=SE[w][1].lower_bound(u);can=out[w][1].lower_bound(u);
        it--;
        can--;
        border=max(u-W*K,*can);
        
        while(*it>=border){
            ll a=*it;
            if(a<0||a>=H*W) break;
            if(chmin(dis[a],dis[u]+1)){
                it--;
                
                Q.push(a);
                SE[w][1].erase(a);
                SE[a/W][0].erase(a);
                //it--;
                
                //cout<<*it<<endl;
            }else break;
        }
        
        
        //cout<<"OK"<<endl;
        //cout<<si(Q)<<endl;
        //break;
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W>>K;
    int h1,w1,h2,w2;cin>>h1>>w1>>h2>>w2;
    h1--;w1--;h2--;w2--;
    
    for(int i=0;i<H;i++){
        string S;cin>>S;
        for(int j=0;j<W;j++){
            if(S[j]=='@'){
                out[i][0].insert(i*W+j);
                out[j][1].insert(i*W+j);
            }else{
                SE[i][0].insert(i*W+j);
                SE[j][1].insert(i*W+j);
            }
            dis[i*W+j]=INF;
            if(i==0) SE[j][1].insert(-INF);
            if(i==0) SE[j][1].insert(INF);
            if(i==0) out[j][1].insert(-INF);
            if(i==0) out[j][1].insert(INF);
            
            if(i==0) SE[j][1].insert(-INF-1);
            if(i==0) SE[j][1].insert(INF+1);
            if(i==0) out[j][1].insert(-INF-1);
            if(i==0) out[j][1].insert(INF+1);
        }
        SE[i][0].insert(-INF);
        SE[i][0].insert(INF);
        out[i][0].insert(-INF);
        out[i][0].insert(INF);
        
        SE[i][0].insert(-INF-1);
        SE[i][0].insert(INF+1);
        out[i][0].insert(-INF-1);
        out[i][0].insert(INF+1);
    }
    
    BFS(h1*W+w1);
    
    ll ans=dis[h2*W+w2];
    if(ans==INF) ans=-1;
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 668260