#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct node{
    int y, x, cost;
    int dir, nokori;

    bool operator<(const node& rhs) const {
        return cost > rhs.cost;
    }
};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int h, w, k;
    cin >> h >> w >> k;

    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    --sy;
    --sx;
    --gy;
    --gx;

    vector<string> c(h);
    rep(i, h){
        cin >> c[i];
    }

    vector< vector< vector<int> > > v(4, vector< vector<int> >(h, vector<int>(w)));
    rep(i, h){
        int now = w;
        rrep(j, w){
            v[0][i][j] = now;
            if(c[i][j] == '@'){
                now = j;
            }
        }
        now = -1;
        rep(j, w){
            v[2][i][j] = now;
            if(c[i][j] == '@'){
                now = j;
            }
        }
    }

    rep(j, w){
        int now = h;
        rrep(i, h){
            v[1][i][j] = now;
            if(c[i][j] == '@'){
                now = i;
            }
        }
        now = -1;
        rep(i, h){
            v[3][i][j] = now;
            if(c[i][j] == '@'){
                now = i;
            }
        }
    }

    vector< vector< vector<int> > > cost(4, vector< vector<int> >(h, vector<int>(w, IINF)));
    priority_queue<node> que;
    rep(i, 4){
        cost[i][sy][sx] = 0;
        que.push({sy, sx, 0, i, 0});
    }

    auto inside = [&](int y, int x){ return 0 <= y && y < h && 0 <= x && x < w; };

    while(!que.empty()){
        node now = que.top();
        que.pop();

        if(cost[now.dir][now.y][now.x] < now.cost){
            continue;
        }

        rep(i, 4){
            int ny = now.y + dy4[i];
            int nx = now.x + dx4[i];

            if(!inside(ny, nx) || c[ny][nx] == '@'){
                continue;
            }

            if(i == now.dir && now.nokori > 0){
                if(chmin(cost[i][ny][nx], now.cost)){
                    que.push({ny, nx, now.cost, i, now.nokori - 1});
                }
            }else{
                if(chmin(cost[i][ny][nx], now.cost + 1)){
                    que.push({ny, nx, now.cost + 1, i, k - 1});
                }
            }
        }
    }

    int ans = IINF;
    rep(i, 4){
        chmin(ans, cost[i][gy][gx]);
    }

    if(ans < IINF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 44916