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

//#pragma comment(linker, "/stack:268435456")

#define ll long long
#define ld long double
#define sz(x) (int) x.size()
#define mp make_pair

#define TASKNAME "robots"

using namespace std;

const int N = 1005;

int n, m, full;

vector<int> g[N * N];
vector<int> h[N * N];
bool a[N * N];
int sorted[N * N];
bool visited[N * N];
int comp[N * N];
int color;
vector<int> adj[N * N];
int cnt[N * N];
int comp_size[N * N];
int repr[N * N];
int used[N * N];

int get(int i, int j) {
	return i * m + j;
}

int tmr;

void dfs1(int v) {
	visited[v] = 1;
	for (int u : g[v]) {
		if (!visited[u]) {
			dfs1(u);
		}
	}

	sorted[tmr++] = v;
}

void dfs2(int v) {
	visited[v] = 1;
	comp[v] = color;
	comp_size[color]++;
	repr[color] = v;
	for (int u : h[v]) {
		if (!visited[u]) {
			dfs2(u);
		}
	}
}

int max_rest;
bool f[N * N];
int cur_ptr;

void reset(int x) {
	fill(f, f + max_rest, 0);
	max_rest = x;
	cur_ptr = 0;
}

int mex() {
	while (cur_ptr < max_rest && f[cur_ptr]) {
		cur_ptr++;
	}

	if (cur_ptr < max_rest) {
		return cur_ptr;
	}
	else {
		return -1;
	}
}

void add(int x) {
	f[x] = 1;
}

vector<pair<int, int>> ans;

void calc(int v, int l = 0) {
	visited[v] = 1;
	int tt = mex();
	if (a[v] && tt != -1) {
		int t = tt - l % max_rest;
		if (t < 0) {
			t += max_rest;
		}
		ans.push_back(mp(v, t + 1));
		add(tt);
	}

	for (int u : h[v]) {
		if (visited[u]) {
			continue;
		}

		calc(u, l + 1);
	}
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#else
	freopen(TASKNAME ".in", "r", stdin);
	freopen(TASKNAME ".out", "w", stdout);
#endif

	cin >> n >> m >> full;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			int id = get(i, j);
			if (c == 'N') {
				a[id] = 1;
				g[id].push_back(get(i - 1, j));
			}
			else if (c == 'n') {
				g[id].push_back(get(i - 1, j));
			}
			else if (c == 'S') {
				a[id] = 1;
				g[id].push_back(get(i + 1, j));
			}
			else if (c == 's') {
				g[id].push_back(get(i + 1, j));
			}
			else if (c == 'E') {
				a[id] = 1;
				g[id].push_back(get(i, j + 1));
			}
			else if (c == 'e') {
				g[id].push_back(get(i, j + 1));
			}
			else if (c == 'W') {
				a[id] = 1;
				g[id].push_back(get(i, j - 1));

			}
			else if (c == 'w') {
				g[id].push_back(get(i, j - 1));
			}
		}
	}

	const int K = (n - 1) * m + (m - 1) + 1;

	for (int i = 0; i < K; i++) {
		for (int j : g[i]) {
			h[j].push_back(i);
		}
	}

	for (int i = 0; i < K; i++) {
		if (!visited[i]) {
			dfs1(i);
		}
	}
	
	fill(visited, visited + K, 0);

	for (int i = K - 1; i >= 0; i--) {
		if (!visited[sorted[i]]) {
			dfs2(sorted[i]);
			color++;
		}
	}

	for (int i = 0; i < K; i++) {
		int c = comp[i];
		cnt[c] += a[i];
		for (int j : g[i]) {
			adj[comp[j]].push_back(c);
		}
	}

	fill(visited, visited + K, 0);

	for (int i = 0; i < color; i++) {
		if (comp_size[i] < 2) continue;
		if (visited[i]) continue;
		reset(comp_size[comp[i]]);
		calc(repr[i]);
	}

	cout << sz(ans) << "\n";
	if (full) {
		for (auto &it : ans) {
			cout << it.first / m + 1 << " " << it.first % m + 1 << " " << it.second << "\n";
		}
	}

#ifdef _DEBUG
	while (1);
#endif
}