#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

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

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

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////


typedef pair<int,int> pii;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    int H, W, K;
    cin >> H >> W >> K;

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    vector<vector<bool>> occ(H+2, vector<bool>(W+2, false));
    vector<vector<bool>> visited(H+2, vector<bool>(W+2, false));
    for (int i = 1; i <= H; i++) {
        string S;
        cin >> S;
        for (int j = 1; j <= W; j++) occ[i][j] = S[j-1] == '@';
    }
    vector<vector<vector<int>>> jump(4, vector<vector<int>>(H+2, vector<int>(W+2, 0)));
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            jump[0][i][j] = i+1;
            jump[1][i][j] = i-1;
            jump[2][i][j] = j+1;
            jump[3][i][j] = j-1;
        }
    }
    vector<vector<int>> dist(H+2, vector<int>(W+2, 1e9));
    dist[x1][y1] = 0;
    queue<pii> q;
    q.emplace(x1, y1);
    visited[x1][y1] = true;
    LL cnt = 0;
    while (!q.empty()) {
        auto pp = q.front();
        q.pop();
        int x = pp.first, y = pp.second;
        int d = dist[x][y];
        vector<int> reachable;
        int it = jump[0][x][y];
        while (it <= min(x+K, H) and !occ[it][y]) {
            reachable.push_back(it);
            if (!visited[it][y]) {
                visited[it][y] = true;
                dist[it][y] = d+1;
                q.emplace(it, y);
            }
            it = jump[0][it][y];
        }
        jump[0][x][y] = it;
        for (int xx: reachable) jump[0][xx][y] = it;
        cnt += reachable.size();

        reachable.clear();
        it = jump[1][x][y];
        while (it >= max(x-K, 1) and !occ[it][y]) {
            reachable.push_back(it);
            if (!visited[it][y]) {
                visited[it][y] = true;
                dist[it][y] = d+1;
                q.emplace(it, y);
            }
            it = jump[1][it][y];
        }
        jump[1][x][y] = it;
        for (int xx: reachable) jump[1][xx][y] = it;
        cnt += reachable.size();

        reachable.clear();
        it = jump[2][x][y];
        while (it <= min(y+K, W) and !occ[x][it]) {
            reachable.push_back(it);
            if (!visited[x][it]) {
                visited[x][it] = true;
                dist[x][it] = d+1;
                q.emplace(x, it);
            }
            it = jump[2][x][it];
        }
        jump[2][x][y] = it;
        for (int yy: reachable) jump[2][x][yy] = it;
        cnt += reachable.size();

        reachable.clear();
        it = jump[3][x][y];
        while (it >= max(y-K, 1) and !occ[x][it]) {
            reachable.push_back(it);
            if (!visited[x][it]) {
                visited[x][it] = true;
                dist[x][it] = d+1;
                q.emplace(x, it);
            }
            it = jump[3][x][it];
        }
        jump[3][x][y] = it;
        for (int yy: reachable) jump[3][x][yy] = it;
        cnt += reachable.size();
    }
    if (dist[x2][y2] > 1e8) cout << -1 << "\n";
    else cout << dist[x2][y2] << "\n";
    assert(cnt <= 4*H*W*4);
}


Measured memory_bytes: 66660