#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxN = 1000;

int n, m, g;
char f[maxN][maxN];
int color[maxN][maxN];
int depth[maxN][maxN];
int tme[maxN][maxN];
pair<int, int> pr[maxN][maxN];
bool used[maxN][maxN];
vector<pair<int, pair<int, int> > > curr;
int ccycx, ccycy, len;

bool inb(int i, int j)
{
	if (i < 0 || j < 0 || i >= n || j >= m)
	{
		return false;
	}
	return true;
}

void fcyc(int i, int j, int d = 0, int pri = -1, int prj = -1)
{
	if (pri == -1)
	{
		pr[i][j] = make_pair(i, j);
	}
	else
	{
		pr[i][j] = make_pair(pri, prj);
	}
	color[i][j] = 1;
	depth[i][j] = d;
	if (f[i][j] == 'E' || f[i][j] == 'e')
	{
		if (color[i][j + 1] == 1)
		{
			len = depth[i][j] - depth[i][j + 1] + 1;
			ccycx = i;
			ccycy = j;
			return;
		}
		else if (color[i][j + 1] == 0)
		{
			fcyc(i, j + 1, d + 1, i, j);
		}
	}
	if (f[i][j] == 'W' || f[i][j] == 'w')
	{
		if (color[i][j - 1] == 1)
		{
			len = depth[i][j] - depth[i][j - 1] + 1;
			ccycx = i;
			ccycy = j;
			return;
		}
		else if (color[i][j - 1] == 0)
		{
			fcyc(i, j - 1, d + 1, i, j);
		}
	}
	if (f[i][j] == 'S' || f[i][j] == 's')
	{
		if (color[i + 1][j] == 1)
		{
			len = depth[i][j] - depth[i + 1][j] + 1;
			ccycx = i;
			ccycy = j;
			return;
		}
		else if (color[i + 1][j] == 0)
		{
			fcyc(i + 1, j, d + 1, i, j);
		}
	}
	if (f[i][j] == 'N' || f[i][j] == 'n')
	{
		if (color[i - 1][j] == 1)
		{
			len = depth[i][j] - depth[i - 1][j] + 1;
			ccycx = i;
			ccycy = j;
			return;
		}
		else if (color[i - 1][j] == 0)
		{
			fcyc(i - 1, j, d + 1, i, j);
		}
	}

	color[i][j] = 2;
	return;

}

void dfs(int i, int j, int l = 0)
{
	used[i][j] = true;

	if(f[i][j] == 'N' || f[i][j] == 'E' || f[i][j] == 'W' || f[i][j] == 'S')
	{
		curr.push_back(make_pair(l, make_pair(i, j)));
	}

	if (!used[pr[i][j].first][pr[i][j].second])
	{
		dfs(pr[i][j].first, pr[i][j].second, l + 1);
	}

	if (inb(i, j + 1) && !used[i][j + 1] && (f[i][j + 1] == 'W' || f[i][j + 1] == 'w'))
	{
		dfs(i, j + 1, l + 1);
	}
	if (inb(i, j - 1) && !used[i][j - 1] && (f[i][j - 1] == 'E' || f[i][j - 1] == 'e'))
	{
		dfs(i, j - 1, l + 1);
	}
	if (inb(i + 1, j) && !used[i + 1][j] && (f[i + 1][j] == 'N' || f[i + 1][j] == 'n'))
	{
		dfs(i + 1, j, l + 1);
	}
	if (inb(i - 1, j) && !used[i - 1][j] && (f[i - 1][j] == 'S' || f[i - 1][j] == 's'))
	{
		dfs(i - 1, j, l + 1);
	}
}

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

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

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

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			tme[i][j] = -1;
			pr[i][j] = make_pair(i, j);
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (color[i][j] == 0 && !used[i][j])
			{
				fcyc(i, j);
				curr.clear();
				dfs(ccycx, ccycy);
				//sort(curr.begin(), curr.end());
				int mxs = 0;
				for (int i = 0; i < min((int)curr.size(), len); i++)
				{
					mxs = max(mxs, curr[i].first - i);
				}
				for (int i = 0; i < min((int)curr.size(), len); i++)
				{
					tme[curr[i].second.first][curr[i].second.second] = (i + mxs) - curr[i].first;
				}
			}
		}
	}

	vector<pair<int, int> > ans;
	int total = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (tme[i][j] != -1)
			{
				total++;
				ans.push_back(make_pair(i, j));
			}
		}
	}

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

	if (g == 1)
	{
		for (int i = 0; i < ans.size(); i++)
		{
			printf("%d %d %d\n", ans[i].first + 1, ans[i].second + 1, tme[ans[i].first][ans[i].second] + 1);
		}
	}




    return 0;
}

