#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

#define pii pair<int, int>

const int N = 1e3;
int was[N][N];
int time = 0;
int color[N][N];
int cycle[N][N]; //which cycle is it?
int cycles = 0;
vector <int> need[N*N];
int csize[N*N];
int pos[N][N];
char c[N][N];
bool haverobot[N][N];
bool marked[N][N];
pii q[N];
int sz;
int n, m, g;

void dfs(int x, int y)
{
	if (color[x][y] != 0) return;
	++color[x][y];
	was[x][y] = time;
	q[sz++] = { x, y };
	int curx, cury;
	curx = x, cury = y;
	if (c[x][y] == 'N')
		curx--;
	if (c[x][y] == 'E')
		cury++;
	if (c[x][y] == 'S')
		curx++;
	if (c[x][y] == 'W')
		cury--;
	if (color[curx][cury] == 0)
	{
		dfs(curx, cury);
		if (color[x][y] == 1) //if we didn't mark it as cycle
			cycle[x][y] = cycle[curx][cury],
			pos[x][y] = pos[curx][cury] + 1;
		return;
	}
	if (was[curx][cury] == time)
	{
		color[x][y] = 2;
		cycle[x][y] = cycles;
		pos[x][y] = 0;
		int ps = -1;
		while (q[sz - 1] != pii(curx, cury))
		{
			--sz;
			++ps;
			color[q[sz].first][q[sz].second] = 2;
			pos[q[sz].first][q[sz].second] = ps;
			cycle[q[sz].first][q[sz].second] = cycles;
			need[cycles].push_back(ps);
		}
		--sz;
		++ps;
		color[q[sz].first][q[sz].second] = 2;
		pos[q[sz].first][q[sz].second] = ps;
		cycle[q[sz].first][q[sz].second] = cycles;
		need[cycles].push_back(ps);
		csize[cycles] = need[cycles].size();
		++cycles;
		return;
	}
	if (color[curx][cury] == 2) //two means it's cycle
	{
		color[x][y] = 1;
		cycle[x][y] = cycle[curx][cury];
		pos[x][y] = pos[curx][cury] + 1;
		return;
	}
	if (color[curx][cury] == 1)
	{
		color[x][y] = 1;
		pos[x][y] = pos[q[sz].first][q[sz].second] + 1;
		cycle[x][y] = cycle[curx][cury];
		return;
	}
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	scanf("%d %d %d", &n, &m, &g);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
		{
			cycle[i][j] = -1;
			scanf(" %c", &c[i][j]);
			if (c[i][j] >= 'a' && c[i][j] <= 'z')
				c[i][j] += 'A' - 'a';
			else
				haverobot[i][j] = 1;
		}
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
		{
			if (color[i][j] == 0)
			{
				sz = 0;
				++time;
				dfs(i, j);
			}
		}

	vector <pair <pii, int> > ans;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (haverobot[i][j])
			{
				int id = cycle[i][j];
				if (need[id].empty())
					continue;
				int now = pos[i][j];
				int time_to_go = csize[id] * (4000000 / csize[id])  - pos[i][j] + need[id].back();
				assert(time_to_go >= 0);
				ans.push_back({{ i, j }, time_to_go});
				need[id].pop_back();				
			}
	cout << ans.size() << endl;
	if (g == 1)
		for (auto x : ans)
			cout << x.first.first + 1 << " " << x.first.second + 1 << " " << x.second << endl;


	return 0;
}