#include <bits/stdc++.h>

#define size(cont) int(cont.size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define llong long long

#ifdef HOME
    #define filename "file"
#else
    #define filename "robots"
#endif // HOME

constexpr llong inf = (llong) 1e9 + 7ll;
char buff[(int) 1e6 + 17];

inline void config_io(bool __fastio)
{
    if (__fastio)
    {
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }

    freopen(filename".in", "r", stdin);

#ifndef HOME
    freopen(filename".out", "w", stdout);
#endif
}

using namespace std;

const int maxn = (int) 2e6 + 17;

int n, m, test, cyc, len, cnt, ans;
vector<int> g[maxn], gr[maxn];
bool st[maxn], used[maxn], incycle[maxn];
int d[maxn], pos[maxn];
set<int> cur;
vector< pair<int, int> > ansv;

void dfs1(int v)
{
    used[v] = true;

    for (auto to : g[v])
        if (used[to])
            cyc = to;
        else
            dfs1(to);
}

void dfs2(int v, int s, int h = 0, int mx = -1)
{
    used[v] = true;
    d[v] = h;

    if (st[v])
    {
        ++cnt;

        int ss = (len + pos[s] - h % len) % len;

        if (!cur.empty())
        {
            auto it = cur.upper_bound(ss);

            if (it == cur.begin())
                it = --cur.end();
            else
                --it;

            int path = h + (len + ss - *it) % len;

            if (mx > path)
                path += len * ((mx - path) / len + int((mx - path) % len != 0));

            mx = path;

//            printf("%d %d: it %d, ss %d\n", v / m + 1, v % m + 1, *it, ss);

            ansv.push_back({v, path});
            cur.erase(it);
        }
    }

    for (auto to : gr[v])
        if (!incycle[to])
            dfs2(to, s, h + 1, mx);
}

void gocyc(int v)
{
    len = 0;
    cnt = 0;
    cur.clear();

    while (true)
    {
        ++len;
        pos[v] = len - 1;
        cur.insert(len - 1);
        incycle[v] = true;
        v = g[v][0];

        if (v == cyc)
            break;
    }

    while (true)
    {
        dfs2(v, v);
        v = g[v][0];

        if (v == cyc)
            break;
    }

    ans += min(len, cnt);
}

void go(int v)
{
    cyc = -1;
    dfs1(v);
    gocyc(cyc);
}

int main()
{
    config_io(false);

    scanf("%d %d %d", &n, &m, &test);

    forn (i, n)
    {
        scanf("%s", buff);

        for (int j = 0; j < m; ++j)
        {
            if (buff[j] == 'N' || buff[j] == 'S' || buff[j] == 'W' || buff[j] == 'E')
                st[i * m + j] = true;

            if (buff[j] == 'N' || buff[j] == 'n')
                g[i * m + j].push_back((i - 1) * m + j);

            if (buff[j] == 'S' || buff[j] == 's')
                g[i * m + j].push_back((i + 1) * m + j);

            if (buff[j] == 'W' || buff[j] == 'w')
                g[i * m + j].push_back(i * m + j - 1);

            if (buff[j] == 'E' || buff[j] == 'e')
                g[i * m + j].push_back(i * m + j + 1);
        }
    }

    for (int i = 0; i < n * m; ++i)
    {
        for (auto to : g[i])
            gr[to].push_back(i);
    }

    for (int i = 0; i < n * m; ++i)
        if (!used[i])
            go(i);

    printf("%d\n", size(ansv));

    if (test == 1)
        for (auto i : ansv)
            printf("%d %d %d\n", i.first / m + 1, i.first % m + 1, i.second + 1);

    return 0;
}
