#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stdio.h>
#include <cmath>
#include <map>
#include <time.h>
#include <cstdio>

using namespace std;

const int N = 1000;
char tab[N][N];
int color[N][N];
int mark[N][N];
int hod[N][N];
int dist[N][N];
int mat[N][N];
int cycle_size[N * N];
int first_pust[N * N];
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };
vector <pair <int, int> > ans;
int ans_time[N][N];
int count_cycle = 1;

void dfs(int x, int y) {
	color[x][y] = 1;
	int xn = x + dx[hod[x][y]];
	int yn = y + dy[hod[x][y]];
	if (color[xn][yn] == 0) {
		dfs(xn, yn);
	}
	else if (color[xn][yn] == 1) {
		mark[xn][yn] = count_cycle;
		count_cycle++;
	}
	color[x][y] = 2;
}

void dfs1(int x, int y) {
	color[x][y] = 2;
	cycle_size[mark[x][y]] = mat[x][y] + 1;
	int xn = x + dx[hod[x][y]];
	int yn = y + dy[hod[x][y]];
	if (color[xn][yn] == 0) {
		mark[xn][yn] = mark[x][y];
		mat[xn][yn] = mat[x][y] + 1;
		dfs1(xn, yn);
	}
}

void dfs2(int x, int y) {
	color[x][y] = 2;
	int xn = x + dx[hod[x][y]];
	int yn = y + dy[hod[x][y]];
	if (color[xn][yn] == 0) {
		dfs2(xn, yn);
		mark[x][y] = mark[xn][yn];
		mat[x][y] = mat[xn][yn] - 1;
		mat[x][y] = (mat[x][y] + cycle_size[mark[xn][yn]]) % cycle_size[mark[xn][yn]];
	}
	else if (color[xn][yn] == 2) {
		mark[x][y] = mark[xn][yn];
		mat[x][y] = mat[xn][yn] - 1;
		mat[x][y] = (mat[x][y] + cycle_size[mark[xn][yn]]) % cycle_size[mark[xn][yn]];
	}
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	int n, m, g;
	cin >> n >> m >> g;
	char rub;
	scanf("%c", &rub);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			scanf("%c", &tab[i][j]);
			if (tab[i][j] == 'N' || tab[i][j] == 'n') {
				hod[i][j] = 0;
			}
			if (tab[i][j] == 'E' || tab[i][j] == 'e') {
				hod[i][j] = 1;
			}
			if (tab[i][j] == 'S' || tab[i][j] == 's') {
				hod[i][j] = 2;
			}
			if (tab[i][j] == 'W' || tab[i][j] == 'w') {
				hod[i][j] = 3;
			}
		}
		scanf("%c", &rub);
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (color[i][j] == 0) {
				dfs(i, j);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			color[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (mark[i][j] > 0 && color[i][j] == 0) {
				mat[i][j] = 0;
				dfs1(i, j);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			color[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (color[i][j] == 0) {
				dfs2(i, j);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (tab[i][j] == 'N' || tab[i][j] == 'E' || tab[i][j] == 'S' || tab[i][j] == 'W') {
				int num_cycle = mark[i][j];
				if (first_pust[num_cycle] < cycle_size[num_cycle]) {
					ans.push_back(make_pair(i, j));
					ans_time[i][j] = 1 + (mat[i][j] - first_pust[num_cycle] + cycle_size[num_cycle]) % cycle_size[num_cycle];
					first_pust[num_cycle]++;

				}
			}
		}
	}

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

/*

3 4 1
SSSS
EESW
ENWW

3 4 1
ssss
eesw
EnwW

4 4 1
essS
Eess
Snww
EeWN

*/