#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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 (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

template<typename M>
class SegmentTree {
private:
    vector<M> data;
    const function<M(M, M)> merge;
    const M identity_element;
    size_t base_data_size;

    void data_size_calc_and_init(size_t N) {
        base_data_size = 1;
        while (base_data_size < N) base_data_size <<= 1;
        data = vector<M>(2 * base_data_size, identity_element);
    }

    void build() {
        for (size_t index = base_data_size - 1; index > 0; index--) {
            data[index] = merge(data[2 * index], data[2 * index + 1]);
        }
    }

public:
    explicit SegmentTree(size_t N, const function<M(M, M)> merge, const M identity_element) : merge(merge), identity_element(identity_element) {
        data_size_calc_and_init(N);
    }

    explicit SegmentTree(const vector<M> &init_data, const function<M(M, M)> merge, const M identity_element) : merge(merge), identity_element(identity_element) {
        data_size_calc_and_init(init_data.size());
        for (size_t index = 0; index < init_data.size(); index++) {
            data[base_data_size + index] = init_data[index];
        }
        build();
    }

    void update(size_t index, M value) {
        index += base_data_size;
        data[index] = value;
        while (index >>= 1) {
            data[index] = merge(data[2 * index], data[2 * index + 1]);
        }
    }

    // [left, right)
    M query(size_t left_index, size_t right_index) {
        M left = identity_element, right = identity_element;
        left_index += base_data_size;
        right_index += base_data_size;
        while (left_index < right_index) {
            if (left_index & 1) left = merge(left, data[left_index++]);
            if (right_index & 1) right = merge(data[--right_index], right);
            left_index >>= 1;
            right_index >>= 1;
        }
        return merge(left, right);
    }

    const M &operator[](const size_t index) {
        return data[index + base_data_size];
    }
};

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    pi start, goal;
    cin >> start.first >> start.second >> goal.first >> goal.second;
    start.first--, start.second--, goal.first--, goal.second--;
    auto merge = [](int a, int b) {
        return min(a, b);
    };
    vector<SegmentTree<int>> HTree(H + 1, SegmentTree<int>(W + 1, merge, INF));
    vector<SegmentTree<int>> WTree(W + 1, SegmentTree<int>(H + 1, merge, INF));
    vector<set<int>> HLeaf(H + 1), WLeaf(W + 1);
    vector<vector<int>> ans(H + 1, vector<int>(W + 1, INF));
    vector<vector<char>> mass(H + 1, vector<char>(W + 1));
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        cin >> mass[i][j];
        if (mass[i][j] == '@') {
            HLeaf[i].insert(j);
            WLeaf[j].insert(i);
        }
    }
    vector<vector<bool>> check(H + 1, vector<bool>(W + 1, false));
    queue<pi> explore;
    check[start.first][start.second] = true;
    ans[start.first][start.second] = 0;
    HTree[start.first].update(start.second, 0);
    WTree[start.second].update(start.first, 0);
    explore.push(start);
    while (!explore.empty()) {
        auto now = explore.front();
        explore.pop();
        int before = INF;
        {
            // height left
            int left = max(0, now.second - K);
            auto itr = HLeaf[now.first].lower_bound(now.second);
            if (itr != HLeaf[now.first].begin()) {
                itr--;
                chmax(left, *itr);
            }
            chmin(before, HTree[now.first].query(left, now.second));
        }
        {
            // weight left
            int left = max(0, now.first - K);
            auto itr = WLeaf[now.second].lower_bound(now.first);
            if (itr != WLeaf[now.second].begin()) {
                itr--;
                chmax(left, *itr);
            }
            chmin(before, WTree[now.second].query(left, now.first));
        }
        {
            // height right
            int right = min(W, now.second + K + 1);
            auto itr = HLeaf[now.first].lower_bound(now.second);
            if (itr != HLeaf[now.first].end()) {
                chmin(right, *itr);
            }
            chmin(before, HTree[now.first].query(now.second + 1, right));
        }
        {
            // wieght right
            int right = min(H, now.first + K + 1);
            auto itr = WLeaf[now.second].lower_bound(now.first);
            if (itr != WLeaf[now.second].end()) {
                chmin(right, *itr);
            }
            chmin(before, WTree[now.second].query(now.first + 1, right));
        }
        if (ans[now.first][now.second] == before + 1) continue;
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (abs(i) == abs(j)) continue;
                if (now.first + i < 0 || now.first + i >= H) continue;
                if (now.second + j < 0 || now.second + j >= W) continue;
                if (mass[now.first + i][now.second + j] == '@') continue;
                explore.emplace(now.first + i, now.second + j);
                check[now.first + i][now.second + j] = true;
            }
        }
        chmin(ans[now.first][now.second], before + 1);
        HTree[now.first].update(now.second, ans[now.first][now.second]);
        WTree[now.second].update(now.first, ans[now.first][now.second]);
    }
    cout << (ans[goal.first][goal.second] >= INF ? -1 : ans[goal.first][goal.second]) << endl;
}

Measured memory_bytes: 179796