#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
string c[1000010];
bool dame[1000010];
int main()
{
    int h, w, k;
    cin>>h>>w>>k;
    int xs, ys, xt, yt;
    cin>>xs>>ys>>xt>>yt;
    xs--; ys--; xt--; yt--;
    for(int i=0; i<h; i++){
        cin>>c[i];
        for(int j=0; j<w; j++){
            if(c[i][j]=='@') dame[i*w+j]=1;
        }
    }
    vector<vector<int>> vx1(h, vector<int>(w)), vx2(h, vector<int>(w)), vy1(h, vector<int>(w)), vy2(h, vector<int>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(c[i][j]=='@'){
                vy1[i][j]=j;
            }else{
                if(j) vy1[i][j]=vy1[i][j-1];
                else vy1[i][j]=-1;
            }
        }
        for(int j=w-1; j>=0; j--){
            if(c[i][j]=='@'){
                vy2[i][j]=j;
            }else{
                if(j<w-1) vy2[i][j]=vy2[i][j+1];
                else vy2[i][j]=w;
            }
        }
    }
    for(int j=0; j<w; j++){
        for(int i=0; i<h; i++){
            if(c[i][j]=='@'){
                vx1[i][j]=i;
            }else{
                if(i) vx1[i][j]=vx1[i-1][j];
                else vx1[i][j]=-1;
            }
        }
        for(int i=h-1; i>=0; i--){
            if(c[i][j]=='@'){
                vx2[i][j]=i;
            }else{
                if(i<h-1) vx2[i][j]=vx2[i+1][j];
                else vx2[i][j]=h;
            }
        }
    }
    int sh=1, sw=1;
    while(sh<h) sh<<=1;
    while(sw<w) sw<<=1;
    const int INF=1e9+7;
    vector<int> d(h*w+h*sw+w*sh, INF);
    deque<int> deq;
    int s=xs*w+ys, t=xt*w+yt;
    d[s]=0;
    deq.push_back(s);
    while(!deq.empty()){
        int z=deq.front(); deq.pop_front();
        if(z>=h*w+h*sw){
            int z1=z-h*w-h*sw;
            int i=z1/(sh), j=z1%(sh);
            if(2*j>=sh){
                if(2*j-sh<h){
                    int nx=(2*j-sh)*w+i;
                    if(d[nx]>d[z] && !dame[nx]){
                        deq.push_front(nx);
                        d[nx]=d[z];
                    }
                }
                if(2*j+1-sh<h){
                    int nx=(2*j+1-sh)*w+i;
                    if(d[nx]>d[z] && !dame[nx]){
                        deq.push_front(nx);
                        d[nx]=d[z];
                    }
                }
            }else{
                int nx=h*w+h*sw+i*sh+2*j;
                if(d[nx]>d[z]){
                    deq.push_front(nx);
                    d[nx]=d[z];
                }
                nx++;
                if(d[nx]>d[z]){
                    deq.push_front(nx);
                    d[nx]=d[z];
                }
            }
        }else if(z>=h*w){
            int z1=z-h*w;
            int i=z1/(sw), j=z1%(sw);
            if(2*j>=sw){
                if(2*j-sw<w){
                    int nx=i*w+2*j-sw;
                    if(d[nx]>d[z] && !dame[nx]){
                        deq.push_front(nx);
                        d[nx]=d[z];
                    }
                }
                if(2*j+1-sw<w){
                    int nx=i*w+2*j+1-sw;
                    if(d[nx]>d[z] && !dame[nx]){
                        deq.push_front(nx);
                        d[nx]=d[z];
                    }
                }
            }else{
                int nx=h*w+i*sw+2*j;
                if(d[nx]>d[z]){
                    deq.push_front(nx);
                    d[nx]=d[z];
                }
                nx++;
                if(d[nx]>d[z]){
                    deq.push_front(nx);
                    d[nx]=d[z];
                }
            }
        }else{
            int i=z/w, j=z%w;
            int i1=max(vx1[i][j]+1, i-k), i2=min(vx2[i][j], i+k+1);
            i1+=sh, i2+=sh;
            for(;i1<i2; i1>>=1, i2>>=1){
                if(i2&1){
                    i2--;
                    if(i2>=sh){
                        if(i2-sh<h){
                            int nx=(i2-sh)*w+j;
                            if(!dame[nx] && d[nx]>d[z]+1){
                                deq.push_back(nx);
                                d[nx]=d[z]+1;
                            }
                        }
                    }else{
                        int nx=h*w+h*sw+sh*j+i2;
                        if(d[nx]>d[z]+1){
                            deq.push_back(nx);
                            d[nx]=d[z]+1;
                        }
                    }
                }
                if(i1&1){
                    if(i1>=sh){
                        if(i1-sh<h){
                            int nx=(i1-sh)*w+j;
                            if(!dame[nx] && d[nx]>d[z]+1){
                                deq.push_back(nx);
                                d[nx]=d[z]+1;
                            }
                        }
                    }else{
                        int nx=h*w+h*sw+sh*j+i1;
                        if(d[nx]>d[z]+1){
                            deq.push_back(nx);
                            d[nx]=d[z]+1;
                        }
                    }
                    i1++;
                }
            }
            i1=max(vy1[i][j]+1, j-k), i2=min(vy2[i][j], j+k+1);
            i1+=sw, i2+=sw;
            for(;i1<i2; i1>>=1, i2>>=1){
                if(i2&1){
                    i2--;
                    if(i2>=sw){
                        if(i2-sw<w){
                            int nx=i*w+i2-sw;
                            if(!dame[nx] && d[nx]>d[z]+1){
                                deq.push_back(nx);
                                d[nx]=d[z]+1;
                            }
                        }
                    }else{
                        int nx=h*w+sw*i+i2;
                        if(d[nx]>d[z]+1){
                            deq.push_back(nx);
                            d[nx]=d[z]+1;
                        }
                    }
                }
                if(i1&1){
                    if(i1>=sw){
                        if(i1-sw<w){
                            int nx=i*w+i1-sw;
                            if(!dame[nx] && d[nx]>d[z]+1){
                                deq.push_back(nx);
                                d[nx]=d[z]+1;
                            }
                        }
                    }else{
                        int nx=h*w+sw*i+i1;
                        if(d[nx]>d[z]+1){
                            deq.push_back(nx);
                            d[nx]=d[z]+1;
                        }
                    }
                    i1++;
                }
            }
        }
    }
    if(d[t]==INF) cout<<-1<<endl;
    else cout<<d[t]<<endl;
    return 0;
}


Measured memory_bytes: 67876