#include <random>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#pragma comment(linker, "/STACK:512000000")
using namespace std;

#define int long long
#define lint long long
#define vint vector<vector<long long>>

pair<int, int> dir[] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1} };

int& gget(pair<int, int> &i, vint& v) {
	return v[i.first][i.second];
}
pair<int, int>& gget(pair<int, int> &i, vector<vector<pair<int, int>>> & v) {
	return v[i.first][i.second];
}

void dfs(int x, int y, vint &p, vint& was, vector<vector<pair<int, int>>> &cy, vint& cy_l) {
	if (was[x][y]) {
		return;
	}
	was[x][y] = 1;

	int tox = x + dir[p[x][y]].first;
	int toy = y + dir[p[x][y]].second;

	if (was[tox][toy] == 2) {
		cy[x][y] = cy[tox][toy];
		cy_l[x][y] = cy_l[tox][toy] + 1;
	}
	else if (was[tox][toy] == 1) {
		cy[x][y] = { tox, toy };
		cy_l[x][y] = 1;
	}
	else if (was[tox][toy] == 0) {
		dfs(tox, toy, p, was, cy, cy_l);
		cy[x][y] = cy[tox][toy];
		cy_l[x][y] = cy_l[tox][toy] + 1;
		//if (make_pair(x, y) == cy[x][y])
		//	cy_l[x][y] = 0;
	}

	was[x][y] = 2;
}

int32_t main() {
	ifstream cin("robots.in");
	ofstream cout("robots.out");
	ios::sync_with_stdio(false);

	int n, m, g;
	cin >> n >> m >> g;
	vector<vector<int>> p(n, vector<int>(m));
	vector<pair<int, int>> pos;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if ('A' <= c && c <= 'Z')
				pos.push_back({ i, j });
			if (c == 'N' || c == 'n')
				p[i][j] = 0;
			if (c == 'W' || c == 'w')
				p[i][j] = 1;
			if (c == 'S' || c == 's')
				p[i][j] = 2;
			if (c == 'E' || c == 'e')
				p[i][j] = 3;
		}
	}

	vector<vector<pair<int, int>>> cy(n, vector<pair<int, int>>(m));
	vector<vector<int>> cy_l(n, vector<int>(m));
	vector<vector<int>> was(n, vector<int>(m, 0));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			dfs(i, j, p, was, cy, cy_l);
		}
	}

	lint used[1001][1001] = {};

	//srand(2283221);
	//random_shuffle(pos.begin(), pos.end());
	const int cant = INT_MAX * 5;
	int q = 0;
	vector<lint> times(pos.size(), cant);
	for (int i = 0; i < pos.size(); i++) {
		auto c = gget(pos[i], cy);
		int cl = gget(c, cy_l);

		int& us = used[c.first][c.second];
		if (us < cl) {
			q++;
			times[i] = us - cy_l[pos[i].first][pos[i].second];
			times[i] = times[i] % cl + cl;
			if (times[i] <= 0)
				times[i] += cl;
			if (times[i] > cl)
				times[i] = times[i] % cl;
			++us;
		}
	}

	cout << q << '\n';

	if (g) {
		for (int i = 0; i < pos.size(); i++) {
			if (times[i] != cant) {
				cout << pos[i].first + 1 << ' ' << pos[i].second + 1 << ' ' << times[i] << '\n';
			}
		}
	}

	return 0;
}