#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;

#define fi(a, b) for (li i = a; i <= b; ++i)
#define fj(a, b) for (li j = a; j <= b; ++j)
#define dfi(a, b) for (li i = a; i >= b; --i)
#define mp make_pair

typedef long long li;
typedef pair<li, li> pl;

const li MAXN = 1e3 + 1;

pl graph[MAXN][MAXN], cur;
li color[MAXN][MAXN], used[MAXN][MAXN], clr;
li cv[MAXN * MAXN + 1], cs[MAXN * MAXN + 1], len[MAXN * MAXN + 1];
li dist[MAXN][MAXN], d;
set<li> time[MAXN * MAXN];
bool f = false;

char c[MAXN][MAXN];

void dfs(pl v) {
	li i = v.first, j = v.second;
	used[i][j] = 1;
	li t = abs(color[graph[i][j].first][graph[i][j].second]);
	if (t != 0) {
		clr = t;
		d = dist[graph[i][j].first][graph[i][j].second] + 1;
	}
	else {
		if (used[graph[i][j].first][graph[i][j].second] == 0)
			dfs(graph[i][j]);
		if (used[graph[i][j].first][graph[i][j].second] == 1) {
			cur = mp(graph[i][j].first, graph[i][j].second);
			f = true;
			d = 0;
		}
	}
	if (f)
		color[i][j] = clr;
	else
		color[i][j] = -clr;
	dist[i][j] = d;
	++d;
	if (v == cur) {
		f = false;
		len[color[i][j]] = d;
	}
	if (c[i][j] >= 'A' && c[i][j] <= 'Z')
		cv[abs(color[i][j])]++;
	if (color[i][j] > 0)
		cs[color[i][j]]++;
	used[i][j] = 2;
}

int main() {
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	li n, m, g;

	cin >> n >> m >> g;

	fi(1, n)
		fj(1, m) {
			cin >> c[i][j];
			if (c[i][j] == 's' || c[i][j] == 'S')
				graph[i][j] = mp(i + 1, j);
			if (c[i][j] == 'n' || c[i][j] == 'N')
				graph[i][j] = mp(i - 1, j);
			if (c[i][j] == 'w' || c[i][j] == 'W')
				graph[i][j] = mp(i, j - 1);
			if (c[i][j] == 'e' || c[i][j] == 'E')
				graph[i][j] = mp(i, j + 1);
		}

	fi(1, n) {
		fj(1, m)
			if (used[i][j] == 0) {
				clr++;
				dfs(mp(i, j));
			}
	}
	/*
	fi(1, n) {
		fj(1, m)
			cout << color[i][j] << ' ';
		cout << endl;
	}
	
	fi(1, n) {
		fj(1, m) {
			cout << dist[i][j] << ' ';
		}
		cout << endl;
	}
	*/
	li ans = 0;

	fi(1, n * m) {
		ans += min(cv[i], cs[i]);
		fj(0, len[i] - 1)
			time[i].insert(j);
	}

	cout << ans << endl;


	if (g == 1) {
		fi(1, n) {
			fj(1, m) {
				li t = abs(color[i][j]);
				if (time[t].empty()) 
					continue;
				set<li>::iterator it = time[t].lower_bound(0);
				cout << i << ' ' << j << ' ' << (*it - dist[i][j] % len[t] + len[t]) << endl;
				time[t].erase(it);
			}
		}
	}

	return 0;
}