#include<bits/stdc++.h>
using namespace std;
int const nax = 1e6 + 10;
char s[nax];
pair <int, int> q[nax];

int main () {
    vector <vector <int>> a;
    vector <vector <int>> dist;
    vector <vector <int>> vis;
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    a.resize(n);

    pair <int, int> st, ed;

    scanf("%d %d", &st.first, &st.second);
    scanf("%d %d", &ed.first, &ed.second);
    -- st.first, -- st.second;
    -- ed.first, -- ed.second;

    for (int i = 0 ; i < n ; ++ i) {
        scanf("%s", s);
        for (int j = 0 ; j < m ; ++ j) {
            a[i].push_back(s[j] == '@' ? 0 : 1);
        }
    }

    vis.resize(n);
    dist.resize(n);
    for (int i = 0 ; i < n ; ++ i) {
        vis[i].resize(m, false);
        dist[i].resize(m, 0);
    }

    set <int> rpos[n];
    set <int> cpos[m];

    for (int i = 0 ; i < n ; ++ i) {
        for (int j = 0 ; j < m ; ++ j)
            rpos[i].insert(j);
    }

    for (int j = 0 ; j < m ; ++ j)
    for (int i = 0 ; i < n ; ++ i) {
        cpos[j].insert(i);
    }
    fprintf(stderr, "ALIVE\n");

    constexpr pair <int, int> invalid_pair = make_pair(-1, -1);

    auto get_neighbour = [&] (int i, int j, int dir) {
        if (dir == 0) {
            auto it = cpos[j].lower_bound(i);
            if (cpos[j].empty() || it == cpos[j].begin()) return invalid_pair;
            -- it;
            if (*it >= i) return invalid_pair;
            return make_pair(*it, j);
        } else if (dir == 1) {
            auto it = cpos[j].upper_bound(i);
            if (it == cpos[j].end()) return invalid_pair;
            return make_pair(*it, j);
        } else if (dir == 2) {
            auto it = rpos[i].lower_bound(j);
            if (rpos[i].empty() || it == rpos[i].begin()) return invalid_pair;
            -- it;
            if (*it >= j) return invalid_pair;
            return make_pair(i, *it);
        } else if (dir == 3) {
            auto it = rpos[i].upper_bound(j);
            if (it == rpos[i].end()) return invalid_pair;
            return make_pair(i, *it);
        } else throw;
    };

    auto erase_from_set = [&] (int i, int j)->void {
        if (cpos[j].find(i) != cpos[j].end())
            cpos[j].erase(cpos[j].find(i));

        if (rpos[i].find(j) != rpos[i].end())
            rpos[i].erase(rpos[i].find(j));
    };

    fprintf(stderr, "ALIVE2\n");


    const int inf = 1e9;
    for (int i = 0 ; i < n; ++ i)
    for (int j = 0 ; j < m; ++ j) {
        dist[i][j] = inf;
    }

    dist[st.first][st.second] = 0;


    int topQ = 0;

    q[topQ ++] = st;
    erase_from_set(st.first, st.second);


    for (int g = 0 ; g < topQ ; ++ g) {

        int x = q[g].first;
        int y = q[g].second;
        int cur_dist = dist[x][y];

        vector <pair <int, int> > to_push;

        for (int dir = 0 ; dir < 4 ; ++ dir) {
            pair <int, int> cur = make_pair(x, y);
            while (true) {
                auto u = get_neighbour(cur.first, cur.second, dir);
                if (u == invalid_pair) break;
                if (!a[u.first][u.second]) break;
                if (abs(u.first - x) + abs(u.second - y) > k) break;
                if (u == cur) break;
                cur = u;
                to_push.push_back(u);
            }
        }

        for (auto &it : to_push) {
            dist[it.first][it.second] = cur_dist + 1;
            erase_from_set(it.first, it.second);
            q[topQ ++] = it;
        }
    }

   /* for (int i = 0 ; i < n;  ++ i, printf("\n"))
        for (int j = 0 ; j < m ; ++ j)
            printf("%d\t", dist[i][j]);*/

    printf("%d\n", dist[ed.first][ed.second] == inf ? -1 : dist[ed.first][ed.second]);
}


Measured memory_bytes: 161284