#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m, K;
    cin >> n >> m >> K;
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    --sx, --sy, --tx, --ty;
    vector<string> M(n);
    for (int i = 0; i < n; ++i) {
        cin >> M[i];
    }


    vector<int> X{-1, 1, 0, 0};
    vector<int> Y{0, 0, -1, 1};

    auto inside = [&](int x, int y) {
        return x >= 0 && x < n && y >= 0 && y < m;
    };
    auto good = [&](int x, int y) {
        return inside(x, y) && (M[x][y] != '@');
    };


    int N = n * m;
    // vector<pair<pair<int,int>,int>> cur(N + 123);
    // vector<pair<pair<int,int>,int>> nxt(N + 123);
    vector<pair<int,int>> cur(N + 123);
    vector<pair<int,int>> nxt(N + 123);
    vector<vector<vector<int>>> dis(n, vector<vector<int>>(m, vector<int>(4, N + 123)));
    vector<vector<bool>> visited(n, vector<bool>(m, false));
    auto ok = [&](int MX) {
        int sz = 0;
        int nsz = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                visited[i][j] = false;
                for (int k = 0; k < 4; ++k) {
                    dis[i][j][k] = N + 123;
                }
            }
        }
        for (int i = 0; i < 4; ++i) {
            dis[sx][sy][i] = 0;
        }
        visited[sx][sy] = true;
        cur[sz++] = make_pair(sx, sy);

        for (int _ = 0; _ < MX && sz > 0; ++_) {
            nsz = 0;
            for (int i = 0; i < sz; ++i) {
                int x = cur[i].first;
                int y = cur[i].second;
                // cout << _ << " : " << x << "," << y << endl;
                int d = N + 123;
                for (int j = 0; j < 4; ++j) {
                    d = min(d, dis[x][y][j]);
                }
                for (int j = 0; j < X.size(); ++j) {
                    int nx = x, ny = y;
                    for (int k = 1; k <= K; ++k) {
                        nx += X[j], ny += Y[j];
                        // cout << " " << nx << " " << ny << " " << K << " " << good(nx, ny) << endl;
                        if (!good(nx, ny)) {
                            break;
                        }
                        if (dis[nx][ny][j] <= d + 1) {
                            break;
                        }
                        dis[nx][ny][j] = d + 1;
                        if (!visited[nx][ny]) {
                            visited[nx][ny] = true;
                            nxt[nsz++] = make_pair(nx, ny);
                        }
                    }
                }
            }
            swap(cur, nxt);
            swap(sz, nsz);
            for (int i = 0; i < sz; ++i) {
                int x = cur[i].first, y = cur[i].second;
                int d = N + 123;
                for (int j = 0; j < 4; ++j) {
                    d = min(d, dis[x][y][j]);
                }
                for (int j = 0; j < 4; ++j) {
                    dis[x][y][j] = d;
                }
            }
        }
        return visited[tx][ty];
    };

    ok(n * m + 1);

    if (visited[tx][ty]) {
        cout << dis[tx][ty][0] << '\n';
    } else {
        cout << -1 << '\n';
    }




    

    return 0;
}

Measured memory_bytes: 129112