#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef tuple<int,Int,Int,Int> T4;

const int INF = 1e8;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    x2--;
    y1--;
    y2--;

    vector<vector<bool>> padma(H, vector<bool>(W,false));
    vector<vector<int>> cnt(H, vector<int>(W, INF));

    rep(i,H) {
        string S;
        cin >> S;
        rep(j,W) {
            if (S[j] == '@') padma[i][j] = true;
        }
    }

    cnt[x1][y1] = 0;

    queue<T4> que; //1つめの変数が1なら横、2なら縦、あとはx,yの順

    int xlim1 = max(0,x1-K);
    for(int i = x1-1; i >= xlim1; i--) {
        if (padma[i][y1]) {
            if (i < x1-1) {
                que.push(make_tuple(1,i+1,x1-1,y1));
            }
            break;
        }
        cnt[i][y1] = 1;
        if (i == xlim1) {
            que.push(make_tuple(1,i,x1-1,y1));
        }
    }

    int xlim2 = min(H-1,x1+K);
    for(int i = x1+1; i <= xlim2; i++) {
        if (padma[i][y1]) {
            if (i > x1+1) {
                que.push(make_tuple(1,x1+1,i-1,y1));
            }
            break;
        }
        cnt[i][y1] = 1;
        if (i == xlim2) {
            que.push(make_tuple(1,x1+1,i,y1));
        }
    }

    int ylim1 = max(0,y1-K);
    for(int j = y1-1; j >= ylim1; j--) {
        if (padma[x1][j]) {
            if (j < y1-1) {
                que.push(make_tuple(2,x1,j+1,y1-1));
            }
            break;
        }
        cnt[x1][j] = 1;
        if (j == ylim1) {
            que.push(make_tuple(2,x1,j,y1-1));
        }
    }

    int ylim2 = min(W-1,y1+K);
    for(int j = y1+1; j <= ylim2; j++) {
        if (padma[x1][j]) {
            if (j > y1+1) {
                que.push(make_tuple(2,x1,y1+1,j-1));
            }
            break;
        }
        cnt[x1][j] = 1;
        if (j == ylim2) {
            que.push(make_tuple(2,x1,y1+1,j));
        }
    }

    if (cnt[x2][y2] != INF) {
        cout << cnt[x2][y2] << endl;
        return 0;
    }

    while(!que.empty()) {
        T4 now = que.front();
        int n = get<0>(now);
        if (n == 1) {
            int xn1 = get<1>(now), xn2 = get<2>(now), yn = get<3>(now);
            for (int i = xn1; i <= xn2; i++) {
                int cntnow = cnt[i][yn];
                int ylimn1 = max(0,yn-K);
                bool INFcnt = false;
                for(int j = yn-1; j >= ylimn1; j--) {
                    if (padma[i][j]) {
                        if (j < yn-1) {
                            if (INFcnt) que.push(make_tuple(2,i,j+1,yn-1));
                        }
                        break;
                    }
                    if (cnt[i][j] > cntnow+1) INFcnt = true;
                    cnt[i][j] = min(cnt[i][j], cntnow+1);
                    if (j == ylimn1) {
                        if (INFcnt) que.push(make_tuple(2,i,j,yn-1));
                    }
                }

                int ylimn2 = min(W-1,yn+K);
                INFcnt = false;
                for(int j = yn+1; j <= ylimn2; j++) {
                    if (padma[i][j]) {
                        if (j > yn+1) {
                            if (INFcnt) que.push(make_tuple(2,i,yn+1,j-1));
                        }
                        break;
                    }
                    if (cnt[i][j] > cntnow+1) INFcnt = true;
                    cnt[i][j] = min(cnt[i][j], cntnow+1);
                    if (j == ylimn2) {
                        if (INFcnt) que.push(make_tuple(2,i,yn+1,j));
                    }
                }
            }
            for (int k = xn1; k <= xn2; k++)  {
                int cntnow = cnt[k][yn];
                if (k > 0 && !padma[k-1][yn] && cnt[k-1][yn] > cntnow) {
                    int xlimm1 = max(0,k-K);
                    bool INFcnt = false;
                    for (int i = k-1; i >= xlimm1; i--) {
                        if (padma[i][yn]) {
                            if (i < k-1) {
                                if (INFcnt) que.push(make_tuple(1,i+1,k-1,yn));
                            }
                            break;
                        }
                        if (cnt[i][yn] > cntnow+1) INFcnt = true;
                        cnt[i][yn] = min(cnt[i][yn], cntnow + 1);
                        if (i == xlimm1) {
                            if (INFcnt) que.push(make_tuple(1,i,k-1,yn));
                        }
                    }
                }
            }
            for (int k = xn2; k >= xn1; k--) {
                int cntnow = cnt[k][yn];
                if (k < H-1 && !padma[k+1][yn] && cnt[k+1][yn] > cntnow) {
                    int xlimm2 = min(H-1,k+K);
                    bool INFcnt = false;
                    for (int i = k+1; i <= xlimm2; i++) {
                        if (padma[i][yn]) {
                            if (i > k+1) {
                                if (INFcnt) que.push(make_tuple(1,k+1,i-1,yn));
                            }
                            break;
                        }
                        if (cnt[i][yn] > cntnow+1) INFcnt = true;
                        cnt[i][yn] = min(cnt[i][yn], cntnow + 1);
                        if (i == xlimm2) {
                            if (INFcnt) que.push(make_tuple(1,k+1,i,yn));
                        }
                    }
                }
            }
        }
        if (n == 2) {
            int xn = get<1>(now), yn1 = get<2>(now), yn2 = get<3>(now);
            for (int j = yn1; j <= yn2; j++) {
                int cntnow = cnt[xn][j];
                int xlimn1 = max(0,xn-K);
                bool INFcnt = false;
                for (int i = xn-1; i >= xlimn1; i--) {
                    if (padma[i][j]) {
                        if (i < xn-1) {
                            if (INFcnt) que.push(make_tuple(1,i+1,xn-1,j));
                        }
                        break;
                    }
                    if (cnt[i][j] > cntnow+1) INFcnt = true;
                    cnt[i][j] = min(cnt[i][j], cntnow+1);
                    if (i == xlimn1) {
                        if (INFcnt) que.push(make_tuple(1,i,xn-1,j));
                    }
                }

                int xlimn2 = min(H-1,xn+K);
                INFcnt = false;
                for (int i = xn+1; i <= xlimn2; i++) {
                    if (padma[i][j]) {
                        if (i > xn+1) {
                            if (INFcnt) que.push(make_tuple(1,xn+1,i-1,j));
                        }
                        break;
                    }
                    if (cnt[i][j] > cntnow+1) INFcnt = true;
                    cnt[i][j] = min(cnt[i][j], cntnow+1);
                    if (i == xlimn2) {
                        if (INFcnt) que.push(make_tuple(1,xn+1,i,j));
                    }
                }
                
            }
            for (int k = yn1; k <= yn2; k++) {
                int cntnow = cnt[xn][k];
                if (k > 0 && !padma[xn][k-1] && cnt[xn][k-1] > cntnow) {
                    int ylimm1 = max(0,k-K);
                    bool INFcnt = false;
                    for (int j = k-1; j >= ylimm1; j--) {
                        if (padma[xn][j]) {
                            if (j < k-1) {
                                if (INFcnt) que.push(make_tuple(2,xn,j+1,k-1));
                            }
                            break;
                        }
                        if (cnt[xn][j] > cntnow+1) INFcnt = true;
                        cnt[xn][j] = min(cnt[xn][j], cntnow + 1);
                        if (j == ylimm1) {
                            if (INFcnt) que.push(make_tuple(2,xn,j,k-1));
                        }
                    }
                }
            }
            for (int k = yn2; k >= yn1; k--) {
                int cntnow = cnt[xn][k];
                if (k < W-1 && !padma[xn][k+1] && cnt[xn][k+1] > cntnow) {
                    int ylimm2 = min(W-1,k+K);
                    bool INFcnt = false;
                    for (int j = k + 1; j <= ylimm2; j++) {
                        if (padma[xn][j]) {
                            if (j > k + 1) {
                                if (INFcnt) que.push(make_tuple(2,xn,k+1,j-1));
                            }
                            break;
                        }
                        if (cnt[xn][j] > cntnow+1) INFcnt = true;
                        cnt[xn][j] = min(cnt[xn][j], cntnow+1);
                        if (j == ylimm2) {
                            if (INFcnt) que.push(make_tuple(2,xn,k+1,j));
                        }
                    }
                }
            }
        }
        que.pop();
    }

    if (cnt[x2][y2] != INF) {
                    cout << cnt[x2][y2] << endl;
                    return 0;
                }

    cout << -1 << endl;



    


}

Measured memory_bytes: 11452