#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>

using namespace std;
vector <string> field;
vector <vector <int> > prv;
vector <vector <int> > cycle;
vector <vector <int> > num;
int defi[1000000], defj[1000000];
int now = -1;
bool used = true;
vector <set <pair <int, int> > > have;
vector <set <int> > need;
vector <vector <int> > to_cycle, where;


void backtrack(int i, int j)
{
    while (prv[i][j] != -1)
    {
        int ni, nj;
        if (prv[i][j] == 1)
            ni = i + 1, nj = j;
        if (prv[i][j] == 2)
            ni = i - 1, nj = j;
        if (prv[i][j] == 3)
            ni = i, nj = j + 1;
        if (prv[i][j] == 4)
            ni = i, nj = j - 1;
        cycle[ni][nj] = cycle[i][j];
        i = ni;
        j = nj;
    }
}


void dfs(int i, int j)
{
    if (field[i][j] == 'N' || field[i][j] == 'n')
    {
        if (prv[i - 1][j] == 0)
        {
            prv[i - 1][j] = 1;
            dfs(i - 1, j);
        }
        else if (cycle[i - 1][j] != -1)
        {
            cycle[i][j] = cycle[i - 1][j];
            backtrack(i, j);
        }
        else
        {
            used = true;
            defi[now] = i; defj[now] = j;
            cycle[i][j] = now;
            backtrack(i, j);
        }
    }
    if (field[i][j] == 's' || field[i][j] == 'S')
    {
        if (prv[i + 1][j] == 0)
        {
            prv[i + 1][j] = 2;
            dfs(i + 1, j);
        }
        else if (cycle[i + 1][j] != -1)
        {
            cycle[i][j] = cycle[i + 1][j];
            backtrack(i, j);
        }
        else
        {
            used = true;
            defi[now] = i; defj[now] = j;
            cycle[i][j] = now;
            backtrack(i, j);
        }
    }
    if (field[i][j] == 'W' || field[i][j] == 'w')
    {
        if (prv[i][j - 1] == 0)
        {
            prv[i][j - 1] = 3;
            dfs(i, j - 1);
        }
        else if (cycle[i][j - 1] != -1)
        {
            cycle[i][j] = cycle[i][j - 1];
            backtrack(i, j);
        }
        else
        {
            used = true;
            defi[now] = i; defj[now] = j;
            cycle[i][j] = now;
            backtrack(i, j);
        }
    }
    if (field[i][j] == 'E' || field[i][j] == 'e')
    {
        if (prv[i][j + 1] == 0)
        {
            prv[i][j + 1] = 4;
            dfs(i, j + 1);
        }
        else if (cycle[i][j + 1] != -1)
        {
            cycle[i][j] = cycle[i][j + 1];
            backtrack(i, j);
        }
        else
        {
            used = true;
            defi[now] = i; defj[now] = j;
            cycle[i][j] = now;
            backtrack(i, j);
        }
    }
}


int cycle_size(int i, int j, int si, int sj, int cnt)
{
    num[i][j] = cnt;
    if (field[i][j] == 'N' || field[i][j] == 'n')
    {
        if (i - 1 == si && j == sj)
            return 1;
        else
            return cycle_size(i - 1, j, si, sj, cnt + 1) + 1;
    }
    if (field[i][j] == 'S' || field[i][j] == 's')
    {
        if (i + 1 == si && j == sj)
            return 1;
        else
            return cycle_size(i + 1, j, si, sj, cnt + 1) + 1;
    }
    if (field[i][j] == 'E' || field[i][j] == 'e')
    {
        if (i == si && j + 1 == sj)
            return 1;
        else
            return cycle_size(i, j + 1, si, sj, cnt + 1) + 1;
    }
    if (field[i][j] == 'w' || field[i][j] == 'W')
    {
        if (i == si && j - 1 == sj)
            return 1;
        else
            return cycle_size(i, j - 1, si, sj, cnt + 1) + 1;
    }
}


void find_dist(int i, int j)
{
    if (field[i][j] == 'N' || field[i][j] == 'n')
    {
        if (to_cycle[i - 1][j] == -1)
            find_dist(i - 1, j);
        to_cycle[i][j] = to_cycle[i - 1][j] + 1;
        where[i][j] = where[i - 1][j];
    }
    if (field[i][j] == 'S' || field[i][j] == 's')
    {
        if (to_cycle[i + 1][j] == -1)
            find_dist(i + 1, j);
        to_cycle[i][j] = to_cycle[i + 1][j] + 1;
        where[i][j] = where[i + 1][j];
    }
    if (field[i][j] == 'E' || field[i][j] == 'e')
    {
        if (to_cycle[i][j + 1] == -1)
            find_dist(i, j + 1);
        to_cycle[i][j] = to_cycle[i][j + 1] + 1;
        where[i][j] = where[i][j + 1];
    }
    if (field[i][j] == 'w' || field[i][j] == 'W')
    {
        if (to_cycle[i][j - 1] == -1)
            find_dist(i, j - 1);
        to_cycle[i][j] = to_cycle[i][j - 1] + 1;
        where[i][j] = where[i][j - 1];
    }
    if ('A' <= field[i][j] && field[i][j] <= 'Z')
        have[cycle[i][j]].insert(make_pair(i, j));
}


int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g;
    ios::sync_with_stdio(false);
    cin >> n >> m >> g;

    field.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> field[i];

    prv.resize(n, vector <int> (m, 0));
    cycle.resize(n, vector <int> (m, -1));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (prv[i][j] == 0)
            {
                if (used)
                    now++;
                used = false;
                prv[i][j] = -1;
                dfs(i, j);
            }
        }
    }
    if (used)
        now++;

    vector <int> sz(now), am(now);
    num.resize(n, vector <int> (m, -1));

    for (int i = 0; i < now; ++i)
    {
        sz[i] = cycle_size(defi[i], defj[i], defi[i], defj[i], 0);
    }
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (field[i][j] == 'N' || field[i][j] == 'S' || field[i][j] == 'E' || field[i][j] == 'W')
                am[cycle[i][j]]++;

    int ans = 0;
    for (int i = 0; i < now; ++i)
        ans += min(am[i], sz[i]);
    cout << ans << endl;

    if (g == 0)
        return 0;



    need.resize(now); have.resize(now);
    to_cycle.resize(n, vector <int> (m, -1));
    where.resize(n, vector <int> (m, -1));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (num[i][j] != -1)
            {
                to_cycle[i][j] = 0;
                where[i][j] = num[i][j];
                if ('a' <= field[i][j] && field[i][j] <= 'z')
                    need[cycle[i][j]].insert(num[i][j]);
                else
                    cout << i + 1 << ' ' << j + 1 << ' ' << 1 << "\n";
            }
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (to_cycle[i][j] == -1)
                find_dist(i, j);
        }
    }
    for (int i = 0; i < now; ++i)
    {
        int start = 0;
        while (need[i].size() > 0 && have[i].size() > 0)
        {
            int j = *need[i].begin();
            int a = have[i].begin()->first, b = have[i].begin()->second;
            int to_wait = (start + 2 * sz[i] + where[a][b] - to_cycle[a][b] % sz[i] - j) % sz[i];
            int t = start + to_wait;
            assert(t < 1000000000);
            cout << a + 1 << ' ' << b + 1 << ' ' << t + 1 << "\n";
            start = t + to_cycle[a][b] + 1  - (t + to_cycle[a][b] + 1) % sz[i] + sz[i];
            need[i].erase(need[i].begin());
            have[i].erase(have[i].begin());
        }
    }
}
