#include <bits/stdc++.h>

using namespace std;

vector <char> mp[1000005];
vector <int> l[1000005], r[1000005], u[1000005], d[1000005], dist[1000005];
vector <bool> vis[1000005];
char s[1000005];

int main() {
	int h, w, k;
	scanf("%d%d%d", &h, &w, &k);
	int sx, sy, tx, ty;
	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	sx--;
	sy--;
	tx--;
	ty--;
	
	for (int i = 0; i < h; i++) {	
		scanf("%s", s);
		for (int j = 0; j < w; j++) mp[i].push_back(s[j]);
		for (int j = 0; j < w; j++) {
			if (s[j] == '@') {
				l[i].push_back(-1);
				r[i].push_back(w);
				u[i].push_back(-1);
				d[i].push_back(h);
			}
			else {
				l[i].push_back(j - 1);
				r[i].push_back(j + 1);
				u[i].push_back(i - 1);
				d[i].push_back(i + 1);
			}
			vis[i].push_back(0);
			dist[i].push_back(0);
		}
	}
	
	queue <pair<int, int>> que;
	que.push(make_pair(sx, sy));
	
	while (que.size()) {
		pair <int, int> now = que.front();
		int curDist = dist[now.first][now.second];
		que.pop();
		
		if (now == make_pair(tx, ty)) return 0 * printf("%d\n", curDist);
		int to, leftEnd, rightEnd, upEnd, downEnd;
		
		//left
		to = l[now.first][now.second];
		while (to >= now.second - k && to != -1) {
			if (!vis[now.first][to] && mp[now.first][to] != '@') {
				dist[now.first][to] = curDist + 1;
				vis[now.first][to] = 1;
				que.push(make_pair(now.first, to));
			}
			to = l[now.first][to];
		}
		leftEnd = to;
		rightEnd = r[now.first][now.second];
		if (leftEnd != -1) r[now.first][leftEnd] = rightEnd;
		if (rightEnd != w) l[now.first][rightEnd] = leftEnd;
		
		to = now.second;
		while (to >= now.second - k && to != -1) {
			int tmp = to;
			to = l[now.first][to];
			r[now.first][tmp] = rightEnd;
			l[now.first][tmp] = leftEnd;
		}
		
		//right
		to = r[now.first][now.second];
		while (to <= now.second + k && to != w) {
			if (!vis[now.first][to] && mp[now.first][to] != '@') {
				dist[now.first][to] = curDist + 1;
				vis[now.first][to] = 1;
				que.push(make_pair(now.first, to));
			}
			to = r[now.first][to];
		}
		leftEnd = l[now.first][now.second];
		rightEnd = to;
		if (rightEnd != w) l[now.first][rightEnd] = leftEnd;
		if (leftEnd != -1) r[now.first][leftEnd] = rightEnd;
		
		to = now.second;
		while (to <= now.second + k && to != w) {
			int tmp = to;
			to = r[now.first][to];
			r[now.first][tmp] = rightEnd;
			l[now.first][tmp] = leftEnd;
		}
		
		//up
		to = u[now.first][now.second];
		while (to >= now.first - k && to != -1) {
			if (!vis[to][now.second] && mp[to][now.second] != '@') {
				dist[to][now.second] = curDist + 1;
				vis[to][now.second] = 1;
				que.push(make_pair(to, now.second));
			}
			to = u[to][now.second];
		}
		upEnd = to;
		downEnd = d[now.first][now.second];
		if (upEnd != -1) d[upEnd][now.second] = downEnd;
		if (downEnd != h) u[downEnd][now.second] = upEnd;
		
		to = now.first;
		while (to >= now.first - k && to != -1) {
			int tmp = to;
			to = u[to][now.second];
			u[tmp][now.second] = upEnd;
			d[tmp][now.second] = downEnd;
		}
		
		//down
		to = d[now.first][now.second];
		while (to <= now.first + k && to != h) {
			if (!vis[to][now.second] && mp[to][now.second] != '@') {
				dist[to][now.second] = curDist + 1;
				vis[to][now.second] = 1;
				que.push(make_pair(to, now.second));
			}
			to = d[to][now.second];
		}
		upEnd = u[now.first][now.second];
		downEnd = to;
		if (downEnd != h) u[downEnd][now.second] = upEnd;
		if (upEnd != -1) d[upEnd][now.second] = downEnd;
		
		to = now.first;
		while (to <= now.first + k && to != h) {
			int tmp = to;
			to = d[to][now.second];
			u[tmp][now.second] = upEnd;
			d[tmp][now.second] = downEnd;
		}
	}
	
	printf("-1\n");
}


Measured memory_bytes: 209912