// ?????¬???????????¬?????? (????°????)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// Ford-Fulkerson ???????????? ?????§??? O( F |E| )
// Bellman-Ford ???????????? ????°??????¨??? O( F |V| |E| )
// Verified: AOJ GRL_6_A (Maximum Flow)

// ???????????¨????????¨???????????????????????????????¨???????????§???????
// ???????????°????????????????§?????????¨??°??????????????¨???

// ????°??????¨?????????????°????????????§???????????§????????????????????????
// ??? ?????????????????????????????????????????????????????£???????°???\?????????

template <typename T>
struct Edge {
    int to; T cap, cost; int rev;
    Edge(int t, T c, int r) : to(t), cap(c), rev(r) {}
    Edge(int t, T ca, T co, int r) : to(t), cap(ca), cost(co), rev(r) {}
};

template <typename T>
using Graph = vector< vector< Edge<T> > >;

template <typename T>
struct Flow {
    vector< vector< Edge<T> > > G;
    const T MAXC = 1 << 30;
    int n;
    vector<bool> used;
    vector<int> prevv, preve, dist;
    Flow(int _n) : G(_n), n(_n), used(_n, false), 
        prevv(n), preve(n), dist(n, MAXC) {}

    // G[e.to][e.rev] ??§?????????????????§??????
    void add_edge(int from, int to, T cap) {
        G[from].push_back(Edge<T>(to, cap, G[to].size()));
        G[to].push_back(Edge<T>(from, 0, G[from].size() - 1));
    }
    void add_edge(int from, int to, T cap, T cost) {
        G[from].push_back(Edge<T>(to, cap, cost, G[to].size()));
        G[to].push_back(Edge<T>(from, 0, -cost, G[from].size() - 1));
    }

    T dfs(int v, int t, T f) {
        if(v == t) return f;
        used[v] = true;
        for(int i=0; i < G[v].size(); i++) {
            Edge<T> &e = G[v][i];
            if(!used[e.to] && e.cap > 0) {
                T d = dfs(e.to, t, min(f, e.cap));
                if(d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T max_flow(int s, int t) {
        T flow = 0;
        while(1) {
            fill(used.begin(), used.end(), false);
            T f = dfs(s, t, INF);
            if(f == 0) return flow;
            flow += f;
        }
    }

    T mincost_flow(int s, int t, T f) {
        T res = 0;
        T ma = MAXC;
        while(f > 0) {
            fill(dist.begin(), dist.end(), ma);
            dist[s] = 0;
            bool update = true;
            while(update) {
                update = false;
                for(int v = 0; v < n; v++) {
                    if(dist[v] == ma) continue;
                    for(int i=0; i<G[v].size(); i++) {
                        Edge<T> &e = G[v][i];
                        if(e.cap>0 && dist[e.to] > dist[v] + e.cost) {
                            dist[e.to] = dist[v] + e.cost;
                            prevv[e.to] = v;
                            preve[e.to] = i;
                            update = true;
                        }
                    }
                }
            }

            if(dist[t] == ma) return -1;
            T d = f;
            for(int v = t; v != s; v = prevv[v]) {
                d = min(d, G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * dist[t];
            for(int v = t; v != s; v = prevv[v]) {
                Edge<T> &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

int N, W[110][110], E[110][110];
bool used[110][110];
char board[110][110];

struct Elem {
    int from, to, ope;
};

signed main() {
    cin >> N;
    rep(i,0,N) rep(j,0,N) cin >> W[i][j];
    rep(i,0,N) rep(j,0,N) cin >> E[i][j];
    rep(i,0,N) rep(j,0,N) cin >> board[i][j];

    Flow<int> fl(2*N+2);
    int source = 2*N, sink = source + 1;
    rep(i,0,N) fl.add_edge(source, i, 1, 0);
    rep(i,0,N) fl.add_edge(N+i, sink, 1, 0);

    int S = 0, cnt = 0;
    rep(i,0,N) rep(j,0,N) {
        if(board[i][j] == 'o') {
            fl.add_edge(i, N+j, 1, -E[i][j]);
            S += E[i][j];
            cnt++;
        }
        else fl.add_edge(i, N+j, 1, W[i][j]);
    }

    cout << fl.mincost_flow(source, sink, N) + S << endl;
    rep(i,0,N) {
        for(auto e : fl.G[i]) {
            if(e.cap == 0) {
                used[i][e.to-N] = true;
                if(board[i][e.to-N] == 'o') cnt--;
                else cnt++;
            }
        }
    }
    
    cout << cnt << endl;
    rep(i,0,N) rep(j,0,N) {
        if(board[i][j] == 'o' && !used[i][j]) printf("%lld %lld erase\n", i+1, j+1);
        if(board[i][j] == '.' &&  used[i][j]) printf("%lld %lld write\n", i+1, j+1);
    }
    return 0;
}

Measured memory_bytes: 4096