#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template <class T> using vvvec = vector<vvec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,K;
    cin >> N >> M >> K;
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    vvec<char> F(N,vec<char>(M));
    for(int i=0;i<N;i++) for(int j=0;j<M;j++) cin >> F[i][j];

    auto in = [&](int x,int y){
        return 0<=x && x<N && 0<=y && y<M && F[x][y]=='.';
    };

    vec<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
    sx--; sy--; gx--; gy--;
    int inf = 1e9;
    vec<set<int>> visrow(N),viscol(M);
    vvec<int> rowS(N,vec<int>(M+1)),colS(N+1,vec<int>(M));
    for(int i=0;i<N;i++) for(int j=0;j<M;j++){
        if(!(i==sx && j==sy) && F[i][j]=='.') visrow[i].insert(j);
        rowS[i][j+1] = rowS[i][j]+(F[i][j]=='@');
    }
    for(int j=0;j<M;j++) for(int i=0;i<N;i++){
        if(!(i==sx && j==sy) && F[i][j]=='.') viscol[j].insert(i);
        colS[i+1][j] = colS[i][j]+(F[i][j]=='@');
    }
    vvec<int> dp(N,vec<int>(M,inf));
    dp[sx][sy] = 0;
    queue<Pa<int,int>> Q;
    Q.push({sx,sy});
    while(!Q.empty()){
        auto [x,y] = Q.front(); Q.pop();
        //R
//        cerr << x << " " << y << "\n";
        set<int>::iterator it = visrow[x].upper_bound(y);
        while(it!=visrow[x].end() && abs(*it-y)<=K){
            int ny = *it;
            if(rowS[x][ny+1]-rowS[x][y]!=0) break;
            if(dp[x][ny]==inf){
                dp[x][ny] = dp[x][y]+1;
                Q.push({x,ny});
            }
            it = visrow[x].erase(it);
            if(it==visrow[x].end()) break;
        }
        //L
        it = visrow[x].upper_bound(y);
        if(it!=visrow[x].begin()){
            it--;
            while(abs(*it-y)<=K){
                int ny = *it;
                if(rowS[x][y+1]-rowS[x][ny]!=0) break;
                if(dp[x][ny]==inf){
                    dp[x][ny] = dp[x][y]+1;
                    Q.push({x,ny});
                }
                it = visrow[x].erase(it);
                if(it==visrow[x].begin()) break;
                it--;
            }
        }
        //U
        it = viscol[y].upper_bound(x);
        while(it!=viscol[y].end() && abs(*it-x)<=K){
            int nx = *it;
            if(colS[nx+1][y]-colS[x][y]!=0) break;
            if(dp[nx][y]==inf){
                dp[nx][y] = dp[x][y]+1;
                Q.push({nx,y});
            }
            it = viscol[y].erase(it);
            if(it==viscol[y].end()) break;
        }
        //D
        it = viscol[y].upper_bound(x);
        if(it!=viscol[y].begin()){
            it--;
            while(abs(*it-x)<=K){
                int nx = *it;
                if(colS[x+1][y]-colS[nx][y]!=0) break;
                if(dp[nx][y]==inf){
                    dp[nx][y] = dp[x][y]+1;
                    Q.push({nx,y});
                }
                it = viscol[y].erase(it);
                if(it==viscol[y].begin()) break;
                it--;
            }
        }
    }
    cout << (dp[gx][gy]==inf? -1:dp[gx][gy]) << "\n";
}

Measured memory_bytes: 163776