#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

int n, m, g, us = 0, sn;
char a[1020][1020];
int cv[1020][1020], usi[1005000], usa[1005000], as[1020][1020], vr[1020][1020], maxt, kl, tim[1020][1020];
vector < pair <int, int> > r;
set <int> usi1[1005000];

inline void dfs(int y, int x) {
	if (cv[y][x] == -1) {
		us++;
		cv[y][x] = us;
		usi[us] = sn - as[y][x];
		vr[y][x] = 1;
		kl = 1;
		return;
	}
	if (cv[y][x] != 0) {
		return;
	}
	cv[y][x] = -1;
	as[y][x] = sn;
	sn++;
	if (a[y][x] == 's') {
		dfs(y + 1, x);
		cv[y][x] = cv[y + 1][x];
	}
	if (a[y][x] == 'n') {
		dfs(y - 1, x);
		cv[y][x] = cv[y - 1][x];
	}
	if (a[y][x] == 'e') {
		dfs(y, x + 1);
		cv[y][x] = cv[y][x + 1];
	}
	if (a[y][x] == 'w') {
		dfs(y, x - 1);
		cv[y][x] = cv[y][x - 1];
	}
	sn--;
	if (kl != usi[us]) {
		kl++;
		vr[y][x] = kl;
	}
	return;
}

inline int fint(int y, int x) {
	int mxt = 0;
	int i = y, j = x, koll = 0;
	while (vr[i][j] == 0) {
		mxt = max(mxt, tim[i][j] - koll + 1);
		if (a[i][j] == 's') {
			i++;
			koll++;
			continue;
		}
		if (a[i][j] == 'n') {
			i--;
			koll++;
			continue;
		}
		if (a[i][j] == 'e') {
			j++;
			koll++;
			continue;
		}
		if (a[i][j] == 'w') {
			j--;
			koll++;
			continue;
		}
		
	}
	for (;; mxt++) {
		if (usi1[cv[i][j]].find(((mxt + koll - vr[i][j]) % usi[cv[i][j]] + usi[cv[i][j]]) % usi[cv[i][j]]) == usi1[cv[i][j]].end()) {
			usi1[cv[i][j]].insert(((mxt + koll - vr[i][j]) % usi[cv[i][j]] + usi[cv[i][j]]) % usi[cv[i][j]]);
			break;
		}
	}
	i = y, j = x;
	koll = 0;
	while (vr[i][j] == 0) {
		tim[i][j] = mxt + koll;
		mxt = max(mxt, tim[i][j] - koll + 1);
		if (a[i][j] == 's') {
			i++;
			koll++;
			continue;
		}
		if (a[i][j] == 'n') {
			i--;
			koll++;
			continue;
		}
		if (a[i][j] == 'e') {
			j++;
			koll++;
			continue;
		}
		if (a[i][j] == 'w') {
			j--;
			koll++;
			continue;
		}
	}
	return mxt;
}

int main() {
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> g;
	for (int i = 1; i <= n; i++) {
		cv[i][0] = cv[i][m + 1] = -2;
		for (int j = 1; j <= m; j++) {
			cv[0][j] = cv[n + 1][j] = -2;
			cin >> a[i][j];
			if (a[i][j] >= 'A' && a[i][j] <= 'Z') {
				r.push_back(make_pair(i, j));
				a[i][j] = a[i][j] - 'A' + 'a';
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (cv[i][j] == 0) {
				sn = 0;
				dfs(i, j);
			}
		}
	}
	int ans = 0;
	if (g == 0) {
		for (int i = 0; i < r.size(); i++) {
			if (usi[cv[r[i].first][r[i].second]] != 0) {
				ans++;
				usi[cv[r[i].first][r[i].second]]--;
			}
		}
		cout << ans;
		return 0;
	}
	for (int i = 0; i <= us; i++) {
		usa[i] = usi[i];
	}
	vector < pair <int, int> > otv;
	for (int i = 0; i < r.size(); i++) {
		if (usa[cv[r[i].first][r[i].second]] != 0) {
			otv.push_back(make_pair(i, fint(r[i].first, r[i].second)));
			usa[cv[r[i].first][r[i].second]]--;
		}
	}
	cout << otv.size() << endl;
	for (int i = 0; i < otv.size(); i++) {
		cout << r[otv[i].first].second << " " << r[otv[i].first].first << " " << otv[i].second << endl;
	}
}