#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
using namespace std;

const int N = 1000010;
int pre[4][N];
int find(int id, int x) {
	if (!pre[id][x]) return x;
	return pre[id][x] = find(id, pre[id][x]);
}

char s[N], str[N];
int nxt[4][N];
// 0: U, 1: D 2: L 3 R
int dis[N];
int n, m, r;

int enc(int x, int y) {
	return (x - 1) * m + y;
}

int main()
{
	scanf("%d%d%d", &n, &m, &r);
	int x1, y1, x2, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%s", str);
		for (int j = 0; j < m; j++)
			s[++cnt] = str[j];
	}

	// up
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			int id = enc(i, j);
			if (s[id] == '@' || i == 1) {
				nxt[0][id] = id;
				continue;
			}
			nxt[0][id] = nxt[0][enc(i - 1, j)];
		}

	// down
	for (int i = n; i >= 1; i--) 
		for (int j = 1; j <= m; j++) {
		    int id = enc(i, j);
	        if (s[id] == '@' || i == n) nxt[1][id] = id;
		    else nxt[1][id] = nxt[1][enc(i + 1, j)];
		}

    for (int i = 1; i <= n; i++) {
	    for (int j = 1; j <= m; j++) {
		    int id = enc(i, j);
		    if (s[id] == '@' || j == 1) nxt[2][id] = id;
			else nxt[2][id] = nxt[2][enc(i, j - 1)];
		}
	}

    for (int i = 1; i <= n; i++) {
	    for (int j = m; j >= 1; j--) {
		    int id = enc(i, j);
		    if (s[id] == '@' || j == m) nxt[3][id] = id;
			else nxt[3][id] = nxt[3][enc(i, j + 1)];
		}
	}

    int st = enc(x1, y1);
    if (s[st] == '@') {
	    printf("-1\n");
	    return 0;
	}
    int ed = enc(x2, y2);
    if (s[ed] == '@') {
	    printf("-1\n");
	    return 0;
	}

    memset(dis, -1, sizeof(dis));
    queue<int> q;
    q.push(st);
    dis[st] = 0;
    while (!q.empty()) {
		int u = q.front();
		q.pop();
		// up
		if (u > m) {
			for (int v = find(0, u - m); ; v = find(0, v)) {
				if (v + 1LL * r * m < u) break;
				int y = nxt[0][u];
				if (v < y) break;
				if (s[v] == '@') break;
				if (dis[v] == -1) {
				    dis[v] = dis[u] + 1;
				    q.push(v);
				}
				if (v > m) {
					int vv = v - m;
					pre[0][v] = vv;
				} else break;
			}
		}
		// down
		if (u + m <= n * m) {
			for (int v = find(1, u + m); ; v = find(1, v)) {
				if (v - 1LL * r * m > u) break;
				int y = nxt[1][u];
				if (v > y) break;
				if (s[v] == '@') break;
				if (dis[v] == -1) {
				    dis[v] = dis[u] + 1;
				    q.push(v);
				}
				if (v + m <= n * m) {
					int vv = v + m;
					pre[1][v] = vv;
				} else break;
			}
		}

		// left
		if (u % m != 1) {
			for (int v = find(2, u - 1); ; v = find(2, v)) {
				if (u - v > r) break;
				int y = nxt[2][u];
				if (v < y) break;
				if (s[v] == '@') break;
			 	if (dis[v] == -1) {
				    dis[v] = dis[u] + 1;
				    q.push(v);
				}
				if (v % m != 1) {
					int vv = v - 1;
					pre[2][v] = vv;
				} else break;
			}
		}
		// right
		if (u % m) {
			for (int v = find(3, u + 1); ; v = find(3, v)) {
				if (v - u > r) break;
				int y = nxt[3][u];
				if (v > y) break;
				if (s[v] == '@') break;
			   	if(dis[v] == -1) {
				    dis[v] = dis[u] + 1;
				    q.push(v);
				}
				if (v % m) {
					int vv = v + 1;
					pre[3][v] = vv;
				} else break;
			}
		}
	}

	printf("%d\n", dis[ed]);
    return 0;
}	


Measured memory_bytes: 38352