#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);
}

typedef pair<pair<ll, ll>, pair<ll, ll>> PP;
int main(int argc, char const *argv[]) {
    ll h,w,k; cin>>h>>w>>k;
    int sy, sx, gy, gx; cin>>sy>>sx>>gy>>gx;
    --sy, --sx;
    --gy, --gx;
    vector<string> s(h);
    rep(i,h) cin>>s[i];

    const vector<P> dd = {{-1,0}, {0,1}, {1,0}, {0,-1}};
    priority_queue<PP, vector<PP>, greater<PP>> pq;
    vector<vector<vector<P>>> dp(h+1, vector<vector<P>>(w+1, vector<P>(4, P(INF,INF))));
    pq.emplace(P(0,0), P(sy,sx));
    rep(i,4) dp[sy][sx][i] = P(0,0);

    while (!pq.empty()) {
        PP cur = pq.top(); pq.pop();
        int cy = cur.second.first; int cx = cur.second.second;
        // cout << "cx = " << cx << ", cy = " << cy << '\n';

        rep(nd,4) {
            int dy = dd[nd].first; int dx = dd[nd].second;
            int ny = cy+dy; int nx = cx+dx;
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (s[ny][nx] == '@') continue;
            
            rep(cd,4) {
                if (nd != cd) {
                    P cost = dp[cy][cx][cd];
                    cost.first += 1; cost.second = 1;
                    if (chmin(dp[ny][nx][nd], cost)) {
                        pq.emplace(dp[ny][nx][nd], P(ny,nx));
                    }
                }
                else {
                    P cost = dp[cy][cx][cd];
                    if (cost.second == k) {
                        cost.first += 1; cost.second = 1;
                    }
                    else {
                        cost.second += 1;
                    }
                    if (chmin(dp[ny][nx][nd], cost)) {
                        pq.emplace(dp[ny][nx][nd], P(ny,nx));
                    }
                }
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 308884