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

int H, W, K;
int X1, Y1, X2, Y2;
vector<vector<char> > c;

pair<int, int> directions[4];
typedef tuple<int, int, int, int> ti;

vector<vector<int> > distMemo[4];
priority_queue<ti, vector<ti>, greater<ti> > minHeap;
void dijkstra()
{
	for(int i = 0; i <= 3; i++)
	{
		minHeap.push(make_tuple(0, X1 - 1, Y1 - 1, i));
		distMemo[i][X1 - 1][Y1 - 1] = 0;
	}
	
	//printf("Start of Dijkstra!\n");
	while(!minHeap.empty())
	{
		ti currPoint = minHeap.top();
		minHeap.pop();
		
		int dist = get<0>(currPoint), currR = get<1>(currPoint), currC = get<2>(currPoint), facing = get<3>(currPoint);
		int deltaR = directions[facing].first, deltaC = directions[facing].second, finalR = currR + deltaR, finalC = currC + deltaC;
		
		//printf("dist = %d, currR = %d, currC = %d, facing = %d\n", dist, currR, currC, facing);
		
		if(dist != distMemo[facing][currR][currC])
			continue;
			
		int newDist;
		if(dist % K != 0)
			newDist = dist - (dist % K) + K;
			
		else
			newDist = dist;
			
		if(facing == 0 || facing == 2)
		{
			if(distMemo[1][currR][currC] == -1 || distMemo[1][currR][currC] > newDist)
			{
				distMemo[1][currR][currC] = newDist;
				minHeap.push(make_tuple(newDist, currR, currC, 1));
			}
			
			if(distMemo[3][currR][currC] == -1 || distMemo[3][currR][currC] > newDist)
			{
				distMemo[3][currR][currC] = newDist;
				minHeap.push(make_tuple(newDist, currR, currC, 3));
			}
		}
		
		else if(facing == 1 || facing == 3)
		{
			if(distMemo[0][currR][currC] == -1 || distMemo[0][currR][currC] > newDist)
			{
				distMemo[0][currR][currC] = newDist;
				minHeap.push(make_tuple(newDist, currR, currC, 0));
			}
			
			if(distMemo[2][currR][currC] == -1 || distMemo[2][currR][currC] > newDist)
			{
				distMemo[2][currR][currC] = newDist;
				minHeap.push(make_tuple(newDist, currR, currC, 2));
			}
		}
			
		if(finalR < 0 || finalR >= H || finalC < 0 || finalC >= W || c[finalR][finalC] == '@')
			continue;
			
		else
		{
			newDist = dist + 1;
			if(distMemo[facing][finalR][finalC] == -1 || distMemo[facing][finalR][finalC] > newDist)
			{
				distMemo[facing][finalR][finalC] = newDist;
				minHeap.push(make_tuple(newDist, finalR, finalC, facing));
			}
		}
	}
	
	//printf("Dijkstra complete!\n");
}

int main()
{
	scanf("%d%d%d", &H, &W, &K);
	scanf("%d%d%d%d", &X1, &Y1, &X2, &Y2);
	
	for(int i = 0; i < H; i++)
	{
		vector<char> emptyVec;
		for(int j = 0; j < W; j++)
		{
			char currChar;
			scanf(" %c", &currChar);
			emptyVec.push_back(currChar);
		}
		c.push_back(emptyVec);
	}
	
	directions[0] = make_pair(0, 1);
	directions[1] = make_pair(-1, 0);
	directions[2] = make_pair(0, -1);
	directions[3] = make_pair(1, 0);
	
	for(int i = 0; i < H; i++)
	{
		vector<int> emptyVec;
		for(int j = 0; j < W; j++)
			emptyVec.push_back(-1);
		distMemo[0].push_back(emptyVec);
	}
	distMemo[1] = distMemo[0];
	distMemo[2] = distMemo[0];
	distMemo[3] = distMemo[0];
	
	//printf("Hello World!\n");
	dijkstra();
	
	int finalAns = -1;
	for(int i = 0; i < 4; i++)
	{
		int ans = distMemo[i][X2 - 1][Y2 - 1];
		if(ans == -1)
			continue;
			
		if(ans % K != 0)
			ans = ans - (ans % K) + K;
			
		if(finalAns == -1 || finalAns > ans)
			finalAns = ans;
	}
	
	if(finalAns == -1)
		printf("-1");
		
	else
		printf("%d", finalAns / K);
}

Measured memory_bytes: 23972