#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
set<int> xs[1000010], ys[1000010];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    int x1, yy1, x2, yy2;
    cin >> x1 >> yy1 >> x2 >> yy2;
    swap(x1, yy1);
    swap(x2, yy2);
    --x1;
    --yy1;
    --x2;
    --yy2;
    int st = yy1 * w + x1, gl = yy2 * w + x2;
    V<string> c(h);
    read(c);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == yy1 && j == x1) continue;
            xs[i].insert(j);
            ys[j].insert(i);
        }
    }
    queue<int> q;
    V<int> d(h * w, INF);
    d[st] = 0;
    q.emplace(st);
    V<int> vs;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        int y = v / w, x = v % w;
        // dump(y, x, d[v]);
        auto it = xs[y].lower_bound(x);
        for (; it != xs[y].end(); it++) {
            if ((*it) > x + k || c[y][(*it)] == '@') break;
            d[y * w + (*it)] = d[v] + 1;
            vs.eb(y * w + (*it));
            q.emplace(y * w + (*it));
        }
        if (!xs[y].empty() && *xs[y].begin() < x) {
            it = prev(xs[y].lower_bound(x));
            for (;; --it) {
                if ((*it) < x - k || c[y][(*it)] == '@') {
                    it++;
                    break;
                }
                vs.eb(y * w + (*it));
                d[y * w + (*it)] = d[v] + 1;
                q.emplace(y * w + (*it));
                if (it == xs[y].begin()) break;
            }
        }
        it = ys[x].lower_bound(y);
        for (; it != ys[x].end(); it++) {
            if ((*it) > y + k || c[(*it)][x] == '@') break;
            d[(*it) * w + x] = d[v] + 1;
            vs.eb((*it) * w + x);
            q.emplace((*it) * w + x);
        }
        if (!ys[x].empty() && *ys[x].begin() < y) {
            it = prev(ys[x].lower_bound(y));
            for (;; --it) {
                if ((*it) < y - k || c[(*it)][x] == '@') {
                    it++;
                    break;
                }
                d[(*it) * w + x] = d[v] + 1;
                vs.eb((*it) * w + x);
                q.emplace((*it) * w + x);
                if (it == ys[x].begin()) break;
            }
        }
        for (auto &e : vs) {
            int ny = e / w, nx = e % w;
            xs[ny].erase(nx);
            ys[nx].erase(ny);
        }
        vs.clear();
    }
    cout << (d[gl] == INF ? -1 : d[gl]) << newl;
}

Measured memory_bytes: 195916