#include <bits/stdc++.h>

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

struct edge {
    ll to, cap, cost, rev;
};

// dijkstra
struct Mincostflow {
    vector<vector<edge>> G;
    VL h, dist, prev, pree;
    ll N;

    Mincostflow(ll size) : N(size) { init(size); };

    void init(ll size) {
        G.resize(N);
        prev.resize(N);
        pree.resize(N);
    }

    void add_edge(ll from, ll to, ll cap, ll cost) {
        G[from].push_back({to, cap, cost, (ll)G[to].size()});
        G[to].push_back({from, 0, -cost, (ll)G[from].size() - 1});
    }

    ll min_cost_flow(ll s, ll t, ll f) {
        ll res = 0;
        h.assign(N, 0);
        while(f > 0) {
            PQG<PL> pq;
            dist.assign(N, LINF);
            dist[s] = 0;
            pq.emplace(dist[s], s);
            while(!pq.empty()) {
                PL p = pq.top();
                pq.pop();
                ll v = p.se;
                REP(i, G[v].size()) {
                    edge &e = G[v][i];
                    if(e.cap > 0 &&
                       dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                        dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                        prev[e.to] = v;
                        pree[e.to] = i;
                        pq.emplace(dist[e.to], e.to);
                    }
                }
            }
            if(dist[t] == LINF) return -1;
            REP(v, N) h[v] += dist[v];
            ll d = f;
            for(int v = t; v != s; v = prev[v]) {
                d = min(d, G[prev[v]][pree[v]].cap);
            }
            f -= d;
            res += d * h[t];
            for(int v = t; v != s; v = prev[v]) {
                edge &e = G[prev[v]][pree[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

ll W[100][100];
ll E[100][100];
string F[100];

struct Ope {
    ll r, c;
    string ope;
};

signed main() {
    LCIN(n);
    REP(i, n) REP(j, n) cin >> W[i][j];
    REP(i, n) REP(j, n) cin >> E[i][j];
    REP(i, n) cin >> F[i];
    ll mi = 0, f = 0;
    REP(i, n) REP(j, n) {
        if(F[i][j] == 'o') {
            mi = min(mi, -E[i][j]);
            f += E[i][j];
        }
    }
    Mincostflow mf(2 * n + 2);
    REP(i, n) REP(j, n) {
        if(F[i][j] == 'o') {
            mf.add_edge(i, n + j, 1, -E[i][j] - mi);
        } else {
            mf.add_edge(i, n + j, 1, W[i][j] - mi);
        }
    }
    REP(i, n) mf.add_edge(2 * n, i, 1, 0);
    REP(i, n) mf.add_edge(n + i, 2 * n + 1, 1, 0);
    f += mf.min_cost_flow(2 * n, 2 * n + 1, n);
    f += mi * n;
    ll cnt = 0;
    vector<Ope> ans;
    REP(i, n) REP(j, n) {
        if((F[i][j] == 'o') == mf.G[i][j].cap) {
            ans.push_back({i + 1, j + 1, F[i][j] == 'o' ? "erase" : "write"});
            cnt++;
        }
    }
    cout << f << "\n";
    cout << cnt << "\n";
    FOREACH(a, ans) cout << a.r << " " << a.c << " " << a.ope << "\n";
}



Measured memory_bytes: 4156