#include <iostream>
#include <cstdlib>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

typedef long long int ll;

const int SIZE = 2000;

char s[SIZE][SIZE];
pair<int, int> type[SIZE][SIZE];
int l = 1;

int len[SIZE * SIZE], cnt[SIZE * SIZE], res[SIZE * SIZE];

void next(int &i, int &j, char c)
{
	if (c == 'n' || c == 'N')
		--i;
	else if (c == 's' || c == 'S')
		++i;
	else if (c == 'w' || c == 'W')
		--j;
	else
		++j;
}

void dfs(int x, int y, int col)
{
	stack<pair<int, int>> st;

	st.push(make_pair(x, y));

	int f = 0;
	while (!st.empty()) {
		x = st.top().first;
		y = st.top().second;

		int i = x, j = y;

		next(i, j, s[i][j]);

		if (type[i][j].first == 0) {
			type[x][y] = make_pair(col, st.size());
			st.push(make_pair(i, j));
		}
		else {
			if (type[i][j].first == col && !f) {
				type[x][y] = make_pair(col, 0);
				len[col] = st.size() - type[i][j].second + 1;
			}
			else
				type[x][y] = make_pair(type[i][j].first, type[i][j].second + 1);

			f = 1;
			st.pop();
		}
	}
}

bool rob(char c)
{
	return c == 'N' || c == 'S' || c == 'E' || c == 'W';
}

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

	int n, m, g;

	scanf("%d %d %d\n", &n, &m, &g);

	for (int i = 0; i < n; i++)
		gets_s(s[i]);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (type[i][j].first == 0)
				dfs(i, j, l++);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (rob(s[i][j]))
				cnt[type[i][j].first]++;

	int sum = 0;
	for (int i = 1; i < l; i++) {
		sum += cnt[i] = min(len[i], cnt[i]);
		res[i] = cnt[i];
	}

	printf("%d\n", sum);

	if (g) {
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if (rob(s[i][j]) && cnt[type[i][j].first] > 0) {
					printf("%d %d %d\n", i + 1, j + 1, res[type[i][j].first] * 2 - type[i][j].second - cnt[type[i][j].first] + n * m - n * m % res[type[i][j].first]);
					cnt[type[i][j].first]--;
				}
	}

	return 0;
}