#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

struct T {
    int y, x, d;
    T(){}
    T(int y, int x, int d):y(y),x(x),d(d){}

    bool operator<(const T &right) const {
        return y < right.y;
    }

    bool operator>(const T &right) const {
        return y > right.y;
    }
};

struct S {
    P p;
    T t;
    S(){}
    S(P p, T t): p(p), t(t){}

    bool operator<(const S &right) const {
        return p == right.p ? t < right.t : p < right.p;
    }

    bool operator>(const S &right) const {
        return p == right.p ? t > right.t : p > right.p;
    }
};


constexpr P dd[4] = {{-1,0}, {0,1}, {1,0}, {0,-1}};
int main(int argc, char const *argv[]) {
    int h,w,k; cin>>h>>w>>k;
    int sx,sy,gx,gy;
    cin>>sy>>sx>>gy>>gx;
    --sx,--sy,--gx,--gy;
    vector<string> g(h);
    rep(i,h) cin>>g[i];

    priority_queue<S, vector<S>, greater<S>> q;
    vector<vector<vector<P>>> dp(h+1, vector<vector<P>> (w+1, vector<P>(4, P(INF,INF))));
    rep(i,4) {
        dp[sy][sx][i] = P(1, 0);
        T t(sy, sx, i);
        S s(dp[sy][sx][i], t);
        q.emplace(s);
    }

    while (!q.empty()) {
        S _cur = q.top(); q.pop();
        T cur = _cur.t;
        int cy = cur.y; int cx = cur.x; int cd = cur.d;
        if (dp[cy][cx][cd] != _cur.p) continue;
        // cout << "cy = " << cy << ", cx = " << cx << ", cd = " << cd << '\n';
        rep(i,4) {
            int ny = cy; int nx = cx; int nd = i;
            P cur_dist = dp[cy][cx][cd];
            cur_dist.first++; cur_dist.second = 0;
            if (chmin(dp[ny][nx][nd], cur_dist)) {
                T t(ny,nx,nd);
                S s(dp[ny][nx][nd], t);
                q.emplace(s);
            }
        }

        P new_dist = dp[cy][cx][cd];
        if (new_dist.second==k) {
            new_dist.second=1;
            new_dist.first++;
        }
        else {
            new_dist.second++;
        }

        int ny = cy+dd[cd].first; int nx = cx+dd[cd].second;
        int nd = cd;
        // cout << "ny = " << ny << ", nx = " << nx << ", nd = " << nd << '\n';
        if (ny < 0 || ny >= h || nx < 0 || nx>=w) continue;
        if (g[ny][nx] == '@') continue;
        if (chmin(dp[ny][nx][nd], new_dist)) {
            T t(ny,nx,nd);
            S s(dp[ny][nx][nd], t);
            q.emplace(s);
        }
    }

    ll ans = INF;
    rep(i,4) chmin(ans, dp[gy][gx][i].first);
    if (ans == INF) {
        cout << -1 << '\n';
    }
    else {
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 308880