// 問題の URL を書いておく
// https://atcoder.jp/contests/abc170/tasks/abc170_f

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#define LOG_LINE \
    do{\
        printf("%s(%d)\n", __FILE__, __LINE__);\
    }while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)
#define LOG_LINE ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

const int INF = numeric_limits<int>::max();

int main(int, const char**)
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<vector<int>>> dists(h, vector<vector<int>>(w, vector<int>(4, INF)));
    int x1, y1, x2, y2;
    cin >> y1 >> x1 >> y2 >> x2;
    x1--; y1--; x2--; y2--;

    vector<string> g(h);
    rep(i, h)
    {
        cin >> g[i];
    }

    struct Info
    {
        int x;
        int y;
        int dir;
        int dist;
        void Dump()
        {

            Print(x);
            Print(y);
            Print(dir);
            Print(dist);
        }
    };

    auto compare = [](const Info& a, const Info& b)
    {
        return b.dist < a.dist;
    };

    priority_queue<Info, vector<Info>, decltype(compare)> q{compare};

    struct Point
    {
        int x;
        int y;
    };

    Point moveMap[] = {
        {1, 0},
        {-1, 0},
        {0, 1},
        {0, -1},
    };

    int dirMap[][3] = {
        {0, 2, 3},
        {1, 2, 3},
        {2, 0, 1},
        {3, 0, 1},
    };

    q.push({x1, y1, 0, 0});
    q.push({x1, y1, 1, 0});
    q.push({x1, y1, 2, 0});
    q.push({x1, y1, 3, 0});

    while(!q.empty())
    {
        auto info = q.top();
        q.pop();
        info.Dump();

        auto& dist = dists[info.y][info.x][info.dir];

        if(info.dist <= dist)
        {
            auto& mv = moveMap[info.dir];
            auto nx = info.x + mv.x;
            auto ny = info.y + mv.y;
            if(nx < 0 || nx >= w || ny < 0 || ny >= h || g[ny][nx] == '@')
            {
                continue;
            }

            for(auto dir : dirMap[info.dir])
            {
                auto ndist = info.dir == dir ? (info.dist + 1) : (info.dist + 1 + k - 1) / k * k;
                if(ndist < dists[ny][nx][dir])
                {
                    dists[ny][nx][dir] = ndist;
                    q.push({nx, ny, dir, ndist});
                }
            }
        }
    }

    auto ans = min(min(dists[y2][x2][0], dists[y2][x2][1]), min(dists[y2][x2][2], dists[y2][x2][3]));
    if(ans == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << (ans + k - 1) / k << endl;
    }

    return 0;
}


Measured memory_bytes: 112552