#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second

using namespace std;

int ct = 0;
int d[1001][1001];
int dis[1001][1001];
bool dr[1001][1001];
int used[1001][1001];
int lvl[1001][1001];
int numc[1001][1001];
vector<pii> drs[500001];
int szc[500001];
int gt[256];
bool gd[256];
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, 1, 0, -1};
const int Tmax = 1e9;

pii dfs(int i, int j, int lv){
    lvl[i][j] = lv;
    used[i][j] = 1;
    int i1 = i + cx[d[i][j]];
    int j1 = j + cy[d[i][j]];
    if (used[i1][j1] == 1){
        ct++;
        numc[i][j] = ct;
        dis[i][j] = 0;
        szc[ct] = lv - lvl[i1][j1] + 1;
    }
    else if (used[i1][j1] == 2){
        numc[i][j] = numc[i1][j1];
        dis[i][j] = dis[i1][j1] + 1;
    }
    else{
        pii p = dfs(i1, j1, lv + 1);
        numc[i][j] = p.F;
        dis[i][j] = p.S + 1;
    }
    used[i][j] = 2;
    if (dr[i][j]){
        drs[numc[i][j]].push_back(pii(i, j));
    }
    return pii(numc[i][j], dis[i][j]);
}

int main()
{
    #ifndef DEBUG
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    #else
    freopen("input.txt", "r", stdin);
    #endif // DEBUG
    int n, m;
    bool g;
    cin >> n >> m >> g;
    gd['N'] = gd['E'] = gd['S'] = gd['W'] = 1;
    gt['E'] = gt['e'] = 1;
    gt['S'] = gt['s'] = 2;
    gt['W'] = gt['w'] = 3;
    string s;
    for (int i = 0; i < n; i++){
        cin >> s;
        for (int j = 0; j < m; j++){
            d[i][j] = gt[s[j]];
            dr[i][j] = gd[s[j]];
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (used[i][j] != 2){
                 dfs(i, j, 0);
            }
        }
    }
    int ans = 0;
    vector<pair<pii, int> > an;
    for (int i = 1; i <= ct; i++){
        int k = min(szc[i], (int)drs[i].size());
        ans += k;
        for (int j = 0; j < k; j++){
            pii p = drs[i][j];
            an.push_back(make_pair(p, Tmax - dis[p.F][p.S] - j));
        }
    }
    cout << ans << "\n";
    if (g){
        for (auto p: an){
            cout << p.F.F + 1 << " " << p.F.S + 1 << " " << p.S << "\n";
        }
    }
    return 0;
}

