#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define MAXN 5000
#define ll long long
using namespace std;

int ky[] = {0, 1, 0, -1};
int kx[] = {-1, 0, 1, 0};
int bd[] = {2, 3, 0, 1};

int n, m, sum, g;
char c;
int used[MAXN * MAXN], was[MAXN * MAXN], num[MAXN * MAXN], timer = 1, t[MAXN * MAXN], tstart;
vector<int> ar[MAXN * MAXN];
vector<pair<int, int>> ans;
int way[MAXN * MAXN];
int len, maxrob;

inline int cnt(int v, int o, int len, int d = 0)
{
    if (used[v])
        return 0;
    num[v] = was[v];
    if (was[v] > 0 && o > 0)
    {
        ans.push_back(make_pair(v, (d + o) % len));
    }
    used[v] = 1;
    for (auto i : ar[v])
    {
        num[v] += cnt(i, o - num[v], len, d + num[v] * 2);
    }
    return num[v];
}

int dfs(int v)
{
    //cerr << v << ' ';
    while(used[way[v]] == 0)
    {
        int res = 0;
        t[v] = timer++;
        if (used[way[v]] == 0)
        {
            if (t[way[v]] < tstart)
                v = way[v];
            else
            {
                len = timer - t[way[v]];
                maxrob = cnt(way[v], len, len);
            }
        }
            else
                return 0;
    }
}




int main()
{
    //cerr << ((int)'a') << ' ' << ((int)'A');
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    cin >> n >> m >> g;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            cin >> c;
            if ((int)c < 97)
                was[i * m + j]++;
            if (c == 'N' || c == 'n')
            {
                way[i * m + j] = (i - 1) * m + j;
                ar[(i - 1) * m + j].push_back(i * m + j);
            }
            if (c == 'E' || c == 'e')
            {
                way[i * m + j] = i * m + j + 1;
                ar[i * m + j + 1].push_back(i * m + j);
            }
            if (c == 'S' || c == 's')
            {
                way[i * m + j] = (i + 1) * m + j;
                ar[(i + 1) * m + j].push_back(i * m + j);
            }
            if (c == 'W' || c == 'w')
            {
                way[i * m + j] = i * m + j - 1;
                ar[i * m + j - 1].push_back(i * m + j);
            }
        }
//    for (int i = 0; i < n * m; i++)
//        if (!used[i])
//            cnt(i);
    int res = 0;
    for (int i = 0; i < n * m; i++)
        if (!used[i])
        {
            tstart = timer;
            len = 0;
            maxrob = 0;
            dfs(i);
            res += min(len, maxrob);
            cerr << '\n';
        }
    cout << res << '\n';
    cerr << res << '\n';
//    for (auto i : ans)
//        cerr << i << ' ';
    int time = 1;
    if (g)
    for (auto i : ans)
    {
        cout << i.first / m + 1 << ' ' << i.first % m + 1 << ' ' << i.second + 1 << '\n';
        time += n * m;
    }
    return 0;
}
