#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename T>
struct Min_Cost_Flow{
    struct edge{
        int to; T cap, cost; int rev;
        edge(int to, T cap, T cost, int rev) : to(to), cap(cap), cost(cost), rev(rev) {} 
    };

    vector<vector<edge>> es;
    vector<T> d;
    vector<int> pre_v, pre_e;
    const T INF_T;

    Min_Cost_Flow(int n) : INF_T(numeric_limits<T>::max()){
        es.resize(n), d.resize(n), pre_v.resize(n), pre_e.resize(n);
    }

    int add_edge(int from, int to, T cap, T cost){
        es[from].eb(to, cap, cost, sz(es[to]));
        es[to].eb(from, 0, -cost, sz(es[from])-1);
        return sz(es[from])-1;
    }

    void bellman_ford(int s){
        fill(all(d), INF_T);
        d[s] = 0;
        while(true){
            bool update = false;
            rep(i, sz(es)){
                if(d[i] == INF_T) continue;
                rep(j, sz(es[i])){
                    edge &e = es[i][j];
                    if(e.cap > 0 && chmin(d[e.to], d[i]+e.cost)){
                        pre_v[e.to] = i, pre_e[e.to] = j;
                        update = true;
                    }
                }
            }
            if(!update) break;
        }
    }

    T min_cost_flow(int s, int t, T flow){
        T ret = 0;
        while(flow > 0){
            bellman_ford(s);
            if(d[t] == INF_T) return ret;
            T f = flow;
            for(int now = t; now != s; now = pre_v[now]){
                chmin(f, es[pre_v[now]][pre_e[now]].cap);
            }
            ret += f*d[t], flow -= f;
            for(int now = t; now != s; now = pre_v[now]){
                edge &e = es[pre_v[now]][pre_e[now]];
                e.cap -= f, es[now][e.rev].cap += f;
            }
        }
        return ret;
    }
};

int main(){
    int N;
    cin >> N;
    int W[N][N], E[N][N];
    rep(i, N){
        rep(j, N) cin >> W[i][j];
    }
    rep(i, N){
        rep(j, N) cin >> E[i][j];
    }
    string S[N];
    rep(i, N) cin >> S[i];
    Min_Cost_Flow<int> G(2*N+2);
    int s = 2*N, t = 2*N+1;
    int ans = 0;
    rep(i, N) G.add_edge(s, i, 1, 0);
    rep(i, N) G.add_edge(N+i, t, 1, 0);
    int id[N][N];
    rep(i, N){
        rep(j, N){
            if(S[i][j] == '.'){
                id[i][j] = G.add_edge(i, N+j, 1, W[i][j]);
            }
            else{
                ans += E[i][j];
                id[i][j] = G.add_edge(i, N+j, 1, -E[i][j]);
            }
        }
    }
    ans += G.min_cost_flow(s, t, N);
    cout << ans << endl;
    vector<pii> used;
    rep(i, N){
        rep(j, N){
            if((S[i][j] == '.') ^ (G.es[i][id[i][j]].cap > 0)) used.eb(i, j);
        }
    }
    cout << sz(used) << endl;
    for(auto &e: used){
        int i, j;
        tie(i, j) = e;
        cout << i+1 << ' ' << j+1 << ' ' << (S[i][j] == '.'? "write" : "erase") << endl;
    }
}


Measured memory_bytes: 3556