#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long a[1005][1005];
long long fl[1005][1005];
long long used[1005][1005];
long long ti[1005][1005];
long long numcycl[1005][1005];
vector <vector <long long> > cycles;
vector <pair <long long, long long> > v;
pair <long long, long long> d[1005][1005];
long long C = 0;
long long cntt[1000005];
long long len[1000005];
vector <pair <pair <long long, long long>, long long> > ans;

void fcycl()
{
	pair <long long, long long> p = v[v.size() - 1];
	//cout << "p " << p.first + 1 << " " << p.second + 1 << " " << ti[p.first][p.second] << endl;
	long long k = v.size() - 2;
	//cout << v.size() << endl;
	//cout << v[k].first + 1 << " " << v[k].second + 1 << endl;
	len[C] = 1;
	while (k >= 0 && (v[k].first != p.first || v[k].second != p.second))
	{
	  //cout << v[k].first + 1 << " " << v[k].second + 1 << endl;
		d[v[k].first][v[k].second].first = 0;
		//cout << "time: " << v[k].first + 1 << " " << v[k].second + 1 << "    " << ti[v[k].first][v[k].second] << " " << ti[p.first][p.second] << endl;
		d[v[k].first][v[k].second].second = ti[v[k].first][v[k].second] - ti[p.first][p.second];
		numcycl[v[k].first][v[k].second] = C;
		k--;
		len[C]++;
	}
	d[p.first][p.second].first = 0;
	d[p.first][p.second].second = 0;
	numcycl[p.first][p.second] = C;
	k--;
	long long cnt = 1;
	for (; k >= 0; k--)
	{
		//cout << "time: " << v[k].first + 1 << " " << v[k].second + 1 << "    " << cnt << endl;
		d[v[k].first][v[k].second].first = cnt;
		d[v[k].first][v[k].second].second = 0;
		numcycl[v[k].first][v[k].second] = C;
		cnt++;
	}
	v.clear();
	C++;
}

pair <long long, long long> f(long long i, long long j, long long k)
{
	//cout << i + 1 << " " << j + 1 << " " << k << endl;
	v.push_back(make_pair(i, j));

	if (used[i][j] == 2)
	{
		//cout << "1!! " << i + 1 << " " << j + 1 << endl;
		fcycl();
		used[i][j] = 1;
		pair <long long, long long> p;
		p.first = -1;
		p.second = -1;
		return p;	
	}
	else if (used[i][j] == 1)
	{
		//cout << "2!! " << i + 1 << " " << j + 1 << endl;
		return make_pair(i, j);	
	}
	ti[i][j] = k;
		
	used[i][j] = 2;
	if (a[i][j] == 1)
	{
		pair <long long, long long> p = f(i - 1, j, k + 1);
		used[i][j] = 1;
		if (p.first == -1)
			return p;
		d[i][j].first = d[p.first][p.second].first + 1;
		d[i][j].second = d[p.first][p.second].second;
		numcycl[i][j] = numcycl[p.first][p.second];
		return make_pair(i, j);
	}
	if (a[i][j] == 2)
	{
		pair <long long, long long> p = f(i, j + 1, k + 1);
		used[i][j] = 1;
		if (p.first == -1)
			return p;
		d[i][j].first = d[p.first][p.second].first + 1;
		d[i][j].second = d[p.first][p.second].second;
		numcycl[i][j] = numcycl[p.first][p.second];
		return make_pair(i, j);
	}	
	if (a[i][j] == 3)
	{
		pair <long long, long long> p = f(i + 1, j, k + 1);
		used[i][j] = 1;
		if (p.first == -1)
			return p;
		d[i][j].first = d[p.first][p.second].first + 1;
		d[i][j].second = d[p.first][p.second].second;
		numcycl[i][j] = numcycl[p.first][p.second];
		//cout << i << " " << j << "   " << d[i][j].first << " " << d[i][j].second << " " << numcycl[i][j] << endl;
		return make_pair(i, j);
	}
	if (a[i][j] == 4)
	{
		pair <long long, long long> p = f(i, j - 1, k + 1);
		used[i][j] = 1;
		if (p.first == -1)
			return p;
		d[i][j].first = d[p.first][p.second].first + 1;
		d[i][j].second = d[p.first][p.second].second;
		numcycl[i][j] = numcycl[p.first][p.second];
		return make_pair(i, j);
	}
}


int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	long long n, m, g;
	cin >> n >> m >> g;

	for (long long i = 0; i < n; i++)
		for (long long j = 0; j < m; j++)
		{
			char c;
			cin >> c;
			if (c >= 'a' && c <= 'z')
			  fl[i][j] = 0;
			else
				fl[i][j] = 1;
			
			if (c == 'n' || c == 'N')
				a[i][j] = 1;
			if (c == 'e' || c == 'E')
				a[i][j] = 2;
			if (c == 's' || c == 'S')
				a[i][j] = 3;
			if (c == 'w' || c == 'W')
				a[i][j] = 4;
	 }

	for (long long i = 0; i < n; i++)
		for (long long j = 0; j < m; j++)
			if (used[i][j] == 0)
			{
				//cout << i + 1 << " " << j + 1 << endl;
				f(i, j, 0);
				v.clear();			
				//cout << endl;
	    }

	//for (long long i = 0; i < n; i++)
		//for (long long j = 0; j < m; j++)
			//cout << i + 1 << " " << j + 1 << " " << d[i][j].first << " " << d[i][j].second << endl;

	long long sum = 0;
	for (long long i = 0; i < n; i++)
		for (long long j = 0; j < m; j++)
	  {
	  	if (fl[i][j] == 1 && cntt[numcycl[i][j]] < len[numcycl[i][j]])
	  	{
	  		sum++;
	  		//cout << i + 1 << " " << j + 1 << "   " << cntt[numcycl[i][j]] << endl;
	  		if (g == 1)
	  			ans.push_back(make_pair(make_pair(i + 1, j + 1), 1000000 - d[i][j].first - (cntt[numcycl[i][j]] - d[i][j].second 
	  										+ len[numcycl[i][j]]) % len[numcycl[i][j]]));
	  		cntt[numcycl[i][j]]++;
	  	}			
	  }                                                             
	cout << sum << endl;
	if (g == 1)
	for (long long i = 0; i < ans.size(); i++)
		cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second << endl;
	
	return 0;
}