#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <cmath>

#pragma comment(linker, "/STACK:256000000")

using namespace std;

typedef long long int ll;
typedef long double ld;

const int INF = (1 << 29) + 5;
const int MAX_N = 1005;

int n, m, type;
char arr[MAX_N][MAX_N];
int graph[MAX_N*MAX_N];
vector<int> rev_graph[MAX_N*MAX_N];
bool ic[MAX_N*MAX_N];
bool rb[MAX_N*MAX_N];
bool used[MAX_N*MAX_N];
bool used_now[MAX_N*MAX_N];
int number[MAX_N*MAX_N];
int cyc_n[MAX_N*MAX_N];
int size_of[MAX_N*MAX_N];
int time_of[MAX_N*MAX_N];
int ptr[MAX_N*MAX_N];
vector<vector<int > > cycl;
vector<int> ans;
int cnt = 0;
int answer = 0;

vector<int> now;
void bfs(int v)
{
	now.clear();
	while (true)
	{
		now.push_back(v);
		used[v] = true;
		used_now[v] = true;
		if (used_now[graph[v]])
		{
			if (!ic[graph[v]])
			{
				for (int i = (int)now.size() - 1; i >= 0; --i)
				{
					ic[now[i]] = true;
					cyc_n[now[i]] = cnt;
					number[now[i]] = (int)now.size() - 1 - i;
					if (now[i] == graph[v])
					{
						size_of[cnt] = number[now[i]] + 1;
						break;
					}
				}
				++cnt;
			}

			for (int i = 0; i < now.size(); ++i)
			{
				used_now[now[i]] = false;
			}
			break;
		}
		else if (used[graph[v]])
		{
			for (int i = 0; i < now.size(); ++i)
			{
				used_now[now[i]] = false;
			}
			break;
		}
		else
		{
			v = graph[v];
		}
	}
}

int dfs(int v, int add, int at, int p, int tm, int len)
{
	int go_now;
	if (rb[v] && size_of[add] > ptr[add])
	{
		++answer;
		go_now = ((tm + len + at - 1)%size_of[add] + size_of[add])%size_of[add];
		if (go_now < ptr[add])
		{
			tm += ptr[add] - go_now;
		}
		if (go_now > ptr[add])
		{
			tm += size_of[add] - go_now + ptr[v];
		}
		++ptr[add];
		//assert(tm <= 1000 * 1000 * 1000);
		time_of[v] = tm;
	}

	for (int i = 0; i < rev_graph[v].size(); ++i)
	{
		if (!ic[rev_graph[v][i]] && rev_graph[v][i] != p)
		{
			tm = dfs(rev_graph[v][i], add, at, v, tm, len + 1);
		}
	}

	return tm;
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);

	scanf("%d %d %d", &n, &m, &type);

	for (int i = 0; i < n; ++i)
	{
		scanf("%s", &arr[i]);
	}

	memset(ic, 0, sizeof(ic));
	memset(rb, 0, sizeof(rb));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (arr[i][j] == 'S')
			{
				graph[i*m + j] = (i + 1)*m + j;
				rev_graph[(i + 1)*m + j].push_back(i*m + j);
				rb[i*m + j] = true;
			}
			else if (arr[i][j] == 's')
			{
				graph[i*m + j] = (i + 1)*m + j;
				rev_graph[(i + 1)*m + j].push_back(i*m + j);
				rb[i*m + j] = false;
			}
			else if (arr[i][j] == 'N')
			{
				graph[i*m + j] = (i - 1)*m + j;
				rev_graph[(i - 1)*m + j].push_back(i*m + j);
				rb[i*m + j] = true;
			}
			else if (arr[i][j] == 'n')
			{
				graph[i*m + j] = (i - 1)*m + j;
				rev_graph[(i - 1)*m + j].push_back(i*m + j);
				rb[i*m + j] = false;
			}
			else if (arr[i][j] == 'W')
			{
				graph[i*m + j] = i*m + j - 1;
				rev_graph[i*m + j - 1].push_back(i*m + j);
				rb[i*m + j] = true;
			}
			else if (arr[i][j] == 'w')
			{
				graph[i*m + j] = i*m + j - 1;
				rev_graph[i*m + j - 1].push_back(i*m + j);
				rb[i*m + j] = false;
			}
			else if (arr[i][j] == 'E')
			{
				graph[i*m + j] = i*m + j + 1;
				rev_graph[i*m + j + 1].push_back(i*m + j);
				rb[i*m + j] = true;
			}
			else if (arr[i][j] == 'e')
			{
				graph[i*m + j] = i*m + j + 1;
				rev_graph[i*m + j + 1].push_back(i*m + j);
				rb[i*m + j] = false;
			}
		}
	}

	memset(used, 0, sizeof(used));

	for (int i = 0; i < n*m; ++i)
	{
		if (!used[i])
		{
			bfs(i);
		}
		time_of[i] = -1;
	}

	/*for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cout << ic[i*m + j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cout << graph[i*m + j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cout << rb[i*m + j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	cout << cnt << endl;*/

	memset(used, 0, sizeof(used));
	memset(ptr, 0, sizeof(ptr));
	for (int i = 0; i < n*m; ++i)
	{
		if (ic[i])
		{
			dfs(i, cyc_n[i], number[i], -1, 1, 0);
		}
	}

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

	if (type == 1)
	{
		for (int i = 0; i < n*m; ++i)
		{
			if (time_of[i] != -1)
			{
				printf("%d %d %d\n", i / m + 1, i%m + 1, time_of[i]);
			}
		}
	}

	fclose(stdin);
	fclose(stdout);

	return 0;
}