#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;

bool add = false;

int pp[100000];

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 tme[1000000];

int now = 2;

int c = 0;

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

int main() {
	cin >> x >> y >> z;
	if (z == 0) {
		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;
				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);
				}
				ans += min(mem, cnt + azaz);
			}
		}
		cout << ans << endl;
	}
	else {
		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;
				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;
				now = 1;
				for (int j = 0; j < mem; j++) {
					pp[j] = 0;
				}
				if (pos != -1) {
					c = cnt;
					dfs2(pos);
					dfs3(pos , -1 , 0 , 0);
				}
				ans += min(mem, cnt + azaz);
			}
		}
		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;
					}
				}
			}
		}
	}
}