#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

#ifdef _DEBUG
#include <fstream>
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <fstream>
ifstream cin("robots.in");
ofstream cout("robots.out");
#endif

int x, y , z;
char a[1000][1000];
bool rob[1000000];

vector < int > g;

#ifndef _DEBUG
vector < int > r[1000000];
#else
vector < int > r[100];
#endif

int u[1000000];
int u1[1000000];
int u2[1000000];
bool cycle[1000000];
int tin[1000000];
int t = 0;

int mem = 0;
int pos = -1;
int cnt = 0;
int azaz = 0;
int mxtme = 0;
int now = 0;

bool easy = true;

bool add = false;

void dfs(int v) {
	u[v] = 1;
	tin[v] = ++t;

	if (!u[g[v]]) {
		dfs(g[v]);
	}
	else {
		if (u[g[v]] == 1) {
			mem = tin[v] - tin[g[v]] + 1;
			pos = g[v];
			add = true;
		}
	}
	if (pos != -1 && add) {
		cnt += rob[v];
		cycle[v] = true;
		if (v == pos)
			add = false;
	}

	u[v] = 2;
}

void dfs2(int v){
	u1[v] = true;
	u[v] = true;
	if (!cycle[v] && rob[v])
		azaz++;
	for (int i = 0; i < r[v].size(); i++) {
		if (!u1[r[v][i]])
			dfs2(r[v][i]);
	}
}

int last = 0;

int tme[1000000];

void dfs3(int v , int h = 1) {
	if (h != 1 && pos == v)
		return;
	if (rob[v]) {
		if (last != -1) {
			tme[v] = h - last;
			mxtme = max(mxtme, tme[v]);
			last = h;
		}
		else {
			tme[v] = 1;
			mxtme = 1;
			last = h;
		}
	}
	dfs3(g[v], h + 1);
}

void dfs4(int v , int h , int ps , int f) {
	u2[v] = true;
	if (rob[v] && now < mem && !cycle[v]) {
		if (ps >= (last + h - now + mem) % mem && ps <= (last + h) % mem) {
			while (ps >= (last + h - now + mem) % mem && ps <= (last + h) % mem) {
				last++;
				last %= mem;
				mxtme++;
			}
			tme[v] = mxtme;
			now++;
			//mxtme++;
		}
		else {
			if (last == -1) {
				last = ps;
				mxtme = h + 1;
				tme[v] = 1;
			}
			else {
				while (ps != (last - now - 1 + h + mem) % mem) {
					last++;
					last %= mem;
					mxtme++;
				}
				now++;
				tme[v] = mxtme;
				//mxtme++;
			}
		}
	}
	for (int i = 0; i < r[v].size(); i++) {
		if (!u2[r[v][i]]) {
			if (!cycle[r[v][i]] && cycle[v])
				dfs4(r[v][i], h + 1, f , f);
			else
				if (!cycle[r[v][i]] && !cycle[v])
					dfs4(r[v][i], h + 1, ps , f);
				else
					dfs4(r[v][i], h , ps , f + 1);
		}
	}
}

int main() {
	cin >> x >> y >> z;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			cin >> a[i][j];
			if (a[i][j] == 'S' || a[i][j] == 'W' || a[i][j] == 'E' || a[i][j] == 'N')
				rob[i * y + j] = true;
			else
				easy = false;
			if (a[i][j] == 'S' || a[i][j] == 's')
				g.push_back((i + 1) * y + j);
			if (a[i][j] == 'N' || a[i][j] == 'n')
				g.push_back((i - 1) * y + j);
			if (a[i][j] == 'W' || a[i][j] == 'w')
				g.push_back(i * y + j - 1);
			if (a[i][j] == 'E' || a[i][j] == 'e')
				g.push_back(i * y + j + 1);
			tme[i * y + j] = -1;
		}
	}
	for (int i = 0; i < g.size(); i++) {
		r[g[i]].push_back(i);
	}

	int ans = 0;
	for (int i = 0; i < x * y; i++) {
		if (!u[i]) {
			mem = 0;
			pos = -1;
			cnt = 0;
			dfs(i);
			azaz = 0;
			if (pos != -1) {
				dfs2(pos);
			}
			last = -1;
			mxtme = 0;
			dfs3(pos);
			last--;
			ans += min(mem, cnt + azaz);
			if (mem != cnt && z == 1) {
				now = cnt;
				dfs4(pos , 0 , -1 , 0);
			}
		}
	}
	cout << ans << endl;
	if (z == 1) {
		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				if (tme[i * y + j] != -1) {
					cout << i + 1 << ' ' << j + 1 << ' ' << tme[i * y + j] << endl;
				}
			}
		}
	}
}