#include <fstream>
#include <utility>
#include <bitset>

using namespace std;

typedef long long ll;

ifstream cin("robots.in");
ofstream cout("robots.out");

const int MAXN = 1000;

char field[MAXN][MAXN];
bool hasRobot[MAXN][MAXN];

int used[MAXN][MAXN];
int cUsed = 0;

pair<int, int> DFS(int i, int j) {
	// cout << i << ' ' << j << '\n';
	used[i][j] = cUsed;
	int ni = i, nj = j;
	if (field[i][j] == 'w') --nj;
	if (field[i][j] == 'e') ++nj;
	if (field[i][j] == 'n') --ni;
	if (field[i][j] == 's') ++ni;
	if (used[ni][nj] == cUsed) return make_pair(ni, nj);
	if (used[ni][nj]) return make_pair(-1, -1);
	return DFS(ni, nj);
}

int GetCycleLen(int i, int j) {
	used[i][j] = cUsed;
	int ni = i, nj = j;
	if (field[i][j] == 'w') --nj;
	if (field[i][j] == 'e') ++nj;
	if (field[i][j] == 'n') --ni;
	if (field[i][j] == 's') ++ni;
	if (used[ni][nj] == cUsed) return 1;
	return GetCycleLen(ni, nj) + 1;
}

bool reverseUsed[MAXN][MAXN];

int ReversedDFS(int i, int j) {
	reverseUsed[i][j] = 1;
	int res = 0;
	res += hasRobot[i][j];
	if (field[i + 1][j] == 'n' && !reverseUsed[i + 1][j])
		res += ReversedDFS(i + 1, j);
	if (field[i - 1][j] == 's' && !reverseUsed[i - 1][j])
		res += ReversedDFS(i - 1, j);
	if (field[i][j - 1] == 'e' && !reverseUsed[i][j - 1])
		res += ReversedDFS(i, j - 1);
	if (field[i][j + 1] == 'w' && !reverseUsed[i][j + 1])
		res += ReversedDFS(i, j + 1);
	return res;
}

bitset<MAXN> usedSet[MAXN];
int cycleLen;
int inCycle[MAXN][MAXN];
pair<int, int> cycle[MAXN];

void SetCycle(int i, int j) {
	usedSet[i][j] = 1;
	--cycleLen;
	int ni = i, nj = j;
	if (field[i][j] == 'w') --nj;
	if (field[i][j] == 'e') ++nj;
	if (field[i][j] == 'n') --ni;
	if (field[i][j] == 's') ++ni;
	if (usedSet[ni][nj]) {
		++cycleLen;
		return;
	}
	SetCycle(ni, nj);
	cycle[cycleLen] = make_pair(i, j);
	++cycleLen;
	inCycle[i][j] = cycleLen;
}

ll ans[MAXN][MAXN];
bitset<MAXN> cycleUsed;
int h = 0;
int cWon = 0;

void SetAns(int i, int j) {
	++h;
	if (cWon < cycleLen && hasRobot[i][j]) {
		int cres = h + MAXN / cycleLen * cycleLen * cWon;
		while (cycleUsed[cres % cycleLen]) {
			++cres;
		}
		ans[i][j] = cres + 1 - h;
		cycleUsed[cres % cycleLen] = 1;
		++cWon;
	}
	if (field[i + 1][j] == 'n' && inCycle[i + 1][j] == -1)
		SetAns(i + 1, j);
	if (field[i - 1][j] == 's' && inCycle[i - 1][j] == -1)
		SetAns(i - 1, j);
	if (field[i][j - 1] == 'e' && inCycle[i][j - 1] == -1)
		SetAns(i, j - 1);
	if (field[i][j + 1] == 'w' && inCycle[i][j + 1] == -1)
		SetAns(i, j + 1);
	--h;
}

int main() {
	int n, m, g;
	cin >> n >> m >> g;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			inCycle[i][j] = -1;
			char c;
			cin >> c;
			if ('A' <= c && c <= 'Z') {
				hasRobot[i][j] = 1;
				c |= 32;
			}
			field[i][j] = c;
		}
	}
	int res = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (used[i][j]) continue;
			++cUsed;
			pair<int, int> cRoot = DFS(i, j);
			if (cRoot.first == -1) continue;
			++cUsed;
			cycleLen = GetCycleLen(cRoot.first, cRoot.second);
			res += min(cycleLen, ReversedDFS(cRoot.first, cRoot.second));
			if (g) {
				SetCycle(cRoot.first, cRoot.second);
				for (int i = 0; i < cycleLen; ++i) {
					cycleUsed[i] = 0;
				}
				for (int w = 0; w < cycleLen; ++w) {
					++h;
					SetAns(cycle[w].first, cycle[w].second);
				}
				cWon = 0;
			}
		}
	}
	cout << res << '\n';
	if (g) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				if (!hasRobot[i][j]) continue;
				if (!ans[i][j]) continue;
				cout << i + 1 << ' ' << j + 1 << ' ' << ans[i][j] << '\n';
			}
		}
	}
}
