#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rall(a) (a).rbegin(), (a).rend()
#define all(a) (a).begin(), (a).end()

struct Cycle {
	int len;
	vector<int> offsets;
};

int dx[300], dy[300];
vector<vector<pair<int, int> > > used, wh;
vector<Cycle> cycles;
vector<pair<int, int> > nowC;
vector<vector<int> > dist;
vector<int> times;
vector<string> mp;
vector<vector<bool> > isInCyc;
int ids = 0, rid, cid, offs, wx, wy;

void dfs(int x, int y) {
	if (used[x][y].first == -1) {
		vector<pair<int, int> > cycle;

		while (nowC.back() != make_pair(x, y)) {
			cycle.push_back(nowC.back());
			nowC.pop_back();
		}

		cycle.push_back({x, y});

		for (int i = 0; i < (int)cycle.size(); i++) {
			used[cycle[i].first][cycle[i].second] = {ids, dist[cycle[i].first][cycle[i].second] % (int)cycle.size()};
			isInCyc[cycle[i].first][cycle[i].second] = 1;
			wh[cycle[i].first][cycle[i].second] = cycle[i];
		}

		cycles.push_back({(int)cycle.size(), {}});

		for (int i = 0; i < (int)cycle.size(); i++) {
			cycles[ids].offsets.push_back(i);
		}

		// int id = used[x][y].first, nowOff = dist[x][y] % cycles[id].len;

		// if (cycles[id].offsets.empty()) return;

		// int needOff = cycles[id].offsets.back();
		// cycles[id].offsets.pop_back();

		// if (nowOff > needOff) {
		// 	needOff += cycles[id].len;
		// }

		// times[rid] = 1 + needOff - nowOff;

		// cid = id;
		// offs = 1;

		wx = x, wy = y;

		ids++;
		// return;
	}
	if (used[x][y].first >= 0) {
		int id = used[x][y].first, nowOff = ((isInCyc[x][y] ? 0 : used[x][y].second) + dist[x][y]) % cycles[id].len;

		if (cycles[id].offsets.empty()) return;

		int needOff = (cycles[id].offsets.back() + used[wh[x][y].first][wh[x][y].second].second) % cycles[id].len;
		cycles[id].offsets.pop_back();

		if (nowOff > needOff) {
			needOff += cycles[id].len;
		}

		times[rid] = 1 + needOff - nowOff;

		cid = id;
		offs = 1;
		wx = wh[x][y].first;
		wy = wh[x][y].second;
		return;
	}

	nowC.push_back({x, y});

	used[x][y] = {-1, 0};

	dist[x + dx[(int)mp[x][y]]][y + dy[(int)mp[x][y]]] = dist[x][y] + 1;
	dfs(x + dx[(int)mp[x][y]], y + dy[(int)mp[x][y]]);

	if (!isInCyc[x][y]) {
		used[x][y] = {cid, offs};
		wh[x][y] = {wx, wy};
		offs = (offs + 1) % cycles[cid].len;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);

	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);

	dx['s'] = 1;
	dy['s'] = 0;
	dx['e'] = 0;
	dy['e'] = 1;
	dx['w'] = 0;
	dy['w'] = -1;
	dx['n'] = -1;
	dy['n'] = 0;

	int n, m, g;
	cin >> n >> m >> g;

	vector<pair<int, int> > robots;

	mp.resize(n);
	used.resize(n, vector<pair<int, int> >(m, {-2, 0}));
	wh.resize(n, vector<pair<int, int> >(m, {-1, -1}));
	dist.resize(n, vector<int>(m));
	isInCyc.resize(n, vector<bool>(m, 0));

	for (int i = 0; i < n; i++) {
		cin >> mp[i];

		for (int j = 0; j < (int)mp[i].size(); j++) {
			if (mp[i][j] == toupper(mp[i][j])) {
				robots.push_back({i, j});
			}

			mp[i][j] = tolower(mp[i][j]);
		}
	}

	times.resize(robots.size(), -1);

	int ans = 0;

	for (int i = 0; i < (int)robots.size(); i++) {
		nowC.clear();
		rid = i;
		dist[robots[i].first][robots[i].second] = 0;
		dfs(robots[i].first, robots[i].second);

		if (times[i] != -1) ans++;
	}

	cout << ans << "\n";

	if (g) {
		for (int i = 0; i < (int)times.size(); i++) {
			if (times[i] != -1) {
				cout << robots[i].first + 1 << " " << robots[i].second + 1 << " " << times[i] << "\n";
			}
		}
	}

	return 0;
}
