#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

#pragma warning (disable:4996)

#define ll long long int
#define mlp make_pair
#define x1 first
#define y1 second

ll n, m, st[3000007], a[3000007], p[3000007], fst[3000007], deep[3000007], cyc[3000007], now, lst[3000007];
vector<ll> v[3000007];
vector<pair<ll, ll> > ans;
string s;

ll find(ll x) {
	if (p[x] == x)return x;
	return p[x] = find(p[x]);
}

void un(ll x, ll y) {
	ll p1 = find(x), p2 = find(y);
	if (p1 == p2)return;
	if (p1 > p2) {
		p[p2] = p1;
	}
	else {
		p[p1] = p2;
	}
}

ll dfs(ll u, ll rng) {
	ll i;
	if (st[u] == 1) {
		fst[now] = u;
		return rng - deep[u] + 1;
	}
	deep[u] = rng + 1;
	st[u] = 1;
	return dfs(v[u][0], deep[u]);
}
void dfs1(ll u) {
	ll i;
	st[u] = 1;
	if (fst[find(u)] == u) {
		deep[u] = 0;
		return;
	}
	if (st[v[u][0]] == 0)dfs1(v[u][0]);
	deep[u] = deep[v[u][0]] + 1;
}

void sol() {
	ll i, j, g;
	for (i = 0; i < 3000007; i++) {
		p[i] = i;
		lst[i] = 0;
		st[i] = 0;
	}
	cin >> n >> m >> g;
	for (i = 0; i < n; i++) {
		cin >> s;
		for (j = 0; j < m; j++) {
			if (s[j] >= 'A'&&s[j] <= 'Z') {
				a[i*m + j] = 1;
				s[j] = s[j] + 'a' - 'A';
			}
			if (s[j] == 's') {
				v[i*m + j].push_back(i*m + m + j);
			}
			if (s[j] == 'w') {
				v[i*m + j].push_back(i*m - 1 + j);
			}
			if (s[j] == 'e') {
				v[i*m + j].push_back(i*m + 1 + j);
			}
			if (s[j] == 'n') {
				v[i*m + j].push_back(i*m - m + j);
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			un(i*m + j, v[i*m + j][0]);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			now = i*m + j;
			if (p[i*m + j] == i*m + j)cyc[i*m + j] = dfs(i*m + j, 0);
			i = i;
		}
	}
	for (i = 0; i < 3000007; i++) {
		st[i] = 0;
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (st[i*m + j] == 0)dfs1(i*m + j);
		}
	}
	ll x, y, z;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (a[i*m + j] == 1) {
				x = find(i*m + j);
				y = (lst[x] - deep[i*m + j] + cyc[x] * (ll)(1e9)) % cyc[x];
				if (lst[x] < cyc[x]) {
					ans.push_back(mlp(i*m + j, y + cyc[x]));
					lst[x]++;
				}
			}
		}
	}
	i = 1;
	cout << ans.size() << endl;
	if (g == 1) {
		for (i = 0; i < ans.size(); i++) {
			printf("%I64d %I64d %I64d\n",ans[i].x1 / m + 1,ans[i].x1%m + 1,ans[i].y1);
		}
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
#endif

	sol();
	return 0;
}