#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;


int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int h, w, k;
    int x1, y1, x2, y2;
    cin >> h >> w >> k;
    cin >> y1 >> x1 >> y2 >> x2;
    x1--;
    y1--;
    x2--;
    y2--;
    char *pmap = new char[1000000];
    int *minstep = new int[1000000];
    bool *dxflag = new bool[1000000];
    bool *dyflag = new bool[1000000];

    for( int i = 0; i < h * w; i++ )
    {
        do
        {
            char c;
            cin >> c;
            if( c == '.' || c == '@' )
            {
                pmap[i] = (c == '.') ? 0 : 1;
                break;
            }
        } while (true);

        minstep[i] = 2 * 1000000;
        dxflag[i] = true;
        dyflag[i] = true;
    }

    queue<int> q;
    q.push(x1 + y1 * w );
    minstep[x1 + y1 * w] = 0;
    int goal = x2 + y2 * w;

    while( !q.empty() )
    {
        int current = q.front();
        q.pop();
        int step = minstep[current];
        int x = current % w;
        int y = current / w;
        if( dxflag[current] )
        {
            for( int l = 1; l <= k; l++)
            {
                int ni = x + l + y * w;
                if( l + x < w && pmap[ni] != 0) break;
                dxflag[x + l - 1 + y * w] = false;
                if( l + x >= w ) break;
                if( ni == goal )
                {
                    cout << step + 1;
                    return 0;
                }
                if( minstep[ni] <= step ) break;
                minstep[ni] = step + 1;
                q.push(ni);
            }
            for( int l = 1; l <= k; l++)
            {
                int ni = x - l + y * w;
                if( x - l >= 0 && pmap[ni] != 0) break;
                dxflag[x - l + 1 + y * w] = false;
                if( x - l < 0 ) break;
                if( ni == goal )
                {
                    cout << step + 1;
                    return 0;
                }
                if( minstep[ni] <= step ) break;
                minstep[ni] = step + 1;
                q.push(ni);
            }
        }
        if( dyflag[current] )
        {
            for( int l = 1; l <= k; l++)
            {
                int ni = x + (y + l) * w;
                if( l + y < h && pmap[ni] != 0) break;
                dyflag[x + (y + l - 1) * w] = false;
                if( l + y >= h ) break;
                if( ni == goal )
                {
                    cout << step + 1;
                    return 0;
                }
                if( minstep[ni] <= step ) break;
                minstep[ni] = step + 1;
                q.push(ni);
            }
            for( int l = 1; l <= k; l++)
            {
                int ni = x + (y - l) * w;
                if( y - l >= 0 && pmap[ni] != 0) break;
                dyflag[x + (y - l + 1) * w] = false;
                if( y - l < 0 ) break;
                if( ni == goal )
                {
                    cout << step + 1;
                    return 0;
                }
                if( minstep[ni] <= step ) break;
                minstep[ni] = step + 1;
                q.push(ni);
            }
        }
    }

    cout << -1;
    return 0;    
}

Measured memory_bytes: 11152