#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

struct state{
    ll x, y, dir;
    bool operator<(const state &right) const{
        if(x==right.x){
            if(y==right.y){
                return dir < right.dir;
            }else{
                return y < right.y;
            }
        }else{
            return x < right.x;
        }
    }
};

vector<ll> dx = {-1, 0, 1, 0};
vector<ll> dy = {0, -1, 0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W, K;
    cin >> H >> W >> K;
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;

    vector<string> S(H);
    REP(i, H) cin >> S[i];

    const ll INF = (1ll<<60);
    using Pi = pair<pll, state>;
    priority_queue< Pi, vector< Pi >, greater< Pi > > qu;
    vector<vector<vector<pll>>> dist(H, vector<vector<pll>>(W, vector<pll>(4, {INF, INF})));

    REP(i, 4){
        dist[x1][y1][i] = {0, 0};
        pll p = {0, 0};
        state s = {x1, y1, i};
        Pi pp = {p, s};
        qu.push(pp);
    }

    while(!qu.empty()){
        pll cost;
        state idx;
        tie(cost, idx) = qu.top();
        qu.pop();
        /*
        cout << idx.x << " " << idx.y << " " << idx.dir << endl; 
        dump(cost)
        cout << endl;
        */
        if(dist[idx.x][idx.y][idx.dir] < cost) continue;
        REP(d, 4){
            ll nx = idx.x + dx[d];
            ll ny = idx.y + dy[d];
            ll ndir = d;
            if(nx<0 or nx > H-1 or ny<0 or ny > W-1) continue;
            if(S[nx][ny] == '@') continue;
            pll next_cost;
            if(cost.second == K){
                next_cost.first =  cost.first + 1;
                next_cost.second = 1;
            }else{
                if(ndir == idx.dir){
                    next_cost.first =  cost.first;
                    next_cost.second = cost.second+1;
                }else{
                    next_cost.first =  cost.first+1;
                    next_cost.second = 1;
                }
            }
            if(dist[nx][ny][ndir] <= next_cost) continue;
            dist[nx][ny][ndir] = next_cost;
            state s = {nx, ny, ndir};
            qu.emplace(next_cost, s);
        }
    }

    ll mi = INF;
    REP(i, 4){
        chmin(mi, dist[x2][y2][i].first);
    }
    
    if(mi == INF){
        cout << -1 << endl;
    }else{
        cout << mi+1 << endl;
    }
    

    return 0;
}

Measured memory_bytes: 207276