#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

vector <vector <char> > gr;
vector <int> parent;
vector <int> size;
vector <int> cycle_size;
vector <int> num_of_robots;
int n, m;
void make_snm(int i, int j) {
    parent[i * m + j] = i * m + j;
    size[i * m + j] = 1;
    if (gr[i][j] == 'S' || gr[i][j] == 'N' || gr[i][j] == 'E' || gr[i][j] == 'W') num_of_robots[i * m + j] = 1;
}
int find_p(int x) {
    if (parent[x] == -1) return -1;
    if (parent[x] == x) return x;
    return parent[x] = find_p(parent[x]);
}

void unite(int l, int r) {
    if (size[l] > size[r]) swap(l, r);
    parent[l] = r;
    size[r] += size[l];
    cycle_size[r] += cycle_size[l];
    num_of_robots[r] += num_of_robots[l];
}
vector <int> time_vhod;
int it;
vector <int> dist;
void obhod (int i, int j, int prev) {
   // cout << i << " " << j << endl;
    it++;
    //cout << it << endl;
    if (time_vhod[i * m + j] == 0) time_vhod[i * m + j] = it;
    if (parent[i * m + j] != -1) {
        int l = find_p(prev);
        int r = find_p(i * m + j);
        if (l == r) {
          //  cout << l << " " << time_vhod[prev] << " " << time_vhod[i * m + j] << endl;
            cycle_size[l] = time_vhod[prev] - time_vhod[i * m + j] + 1;
            dist[prev] = 0;
        } else {
            unite(l, r);
            dist[prev] = dist[i * m + j] + 1;
        }
        return;
    }
    make_snm(i, j);
    if (prev != -1) unite(i * m + j, find_p(prev));
    if (gr[i][j] == 'N' || gr[i][j] == 'n') {
        obhod(i - 1, j, i * m + j);
        if (prev != -1) dist[prev] = dist[i * m + j] + 1;
        return;
    }
    if (gr[i][j] == 'S' || gr[i][j] == 's') {
        obhod(i + 1, j, i * m + j);
         if (prev != -1) dist[prev] = dist[i * m + j] + 1;
        return;
    }
    if (gr[i][j] == 'E' || gr[i][j] == 'e') {
        obhod(i, j + 1, i * m + j);
         if (prev != -1) dist[prev] = dist[i * m + j] + 1;
        return;
    }
    if (gr[i][j] == 'W' || gr[i][j] == 'w') {
        obhod(i, j - 1, i * m + j);
        if (prev != -1)  dist[prev] = dist[i * m + j] + 1;
        return;
    }
}


int main() {
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
   int g;
   cin >> n >> m >> g;
   for (int i = 0; i < n; i++) {
        gr.push_back(vector <char> (m, 0));
        for (int j = 0; j < m; j++) {
            cin >> gr[i][j];
        }
   }
   dist.resize(n * m, -1);
   size.resize(n * m, 0);
   cycle_size.resize(n * m, 0);
   num_of_robots.resize(n * m, 0);
   parent.resize(n * m, -1);
   time_vhod.resize(n * m, 0);
   for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            it = 0;
            if (parent[i * m + j] != -1) continue;
            obhod(i, j, -1);
        }
   }
   long long cnt = 0;
   //vector <int> used(n * m, 0);
   vector <pair <int, pair <int, int> > > ans;
   vector <int> prev_m(n * m, 0);
   for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            //cout << dist[i * m + j] << endl;
            int k = find_p(i * m + j);
            if (cycle_size[k] > 0 && (gr[i][j] == 'S' || gr[i][j] == 'N' || gr[i][j] == 'E' || gr[i][j] == 'W')) {
                cnt++;
                cycle_size[k]--;
                if (prev_m[k] + 1 <= dist[i * m + j]) {
                    prev_m[k] = dist[i * m + j];
                    ans.push_back({0, {i + 1, j + 1}});
                } else {
                    prev_m[k] = prev_m[k] + 1;
                    ans.push_back({prev_m[k] - dist[i * m + j] + 1, {i + 1, j + 1}});
                }
                 //min(cycle_size[k], num_of_robots[k]);
                //cout << cycle_size[k] << " " <<  num_of_robots[k] << endl;
            }
        }
   }
   cout << cnt << endl;
   if (g == 1) {
        for (int i = 0; i < ans.size(); i++) {
            cout << ans[i].second.first << " " << ans[i].second.second << " " << ans[i].first << endl;
        }
   }
}
/*
    3 4 0
    SSSS
    EESW
    ENWW
*/
