#include <bits/stdc++.h>
using namespace std;
using i64=int_fast64_t;
using pii=pair<int,int>;
template <class T> using minheap=priority_queue<T,vector<T>,greater<T>>;
#define fir first
#define sec second
#define mkp make_pair
#define all(v) begin(v),end(v)

int n;
int w[120][120],e[120][120];
int cost[120][120];
string f[120];
vector<tuple<int,int,int,int>> adj[250];
vector<tuple<int,int,string>> ope[120][120];

void add_edge(int x,int y,int cap,int cos) {
    int xx=adj[x].size();
    int yy=adj[y].size();
    adj[x].emplace_back(y,cap,cos,yy);
    adj[y].emplace_back(x,0,-cos,xx);
}

int dist[250];
i64 h[250];
pii _prev[250];
int findway(int s,int t) {
    memset(_prev,0,sizeof(_prev));
    fill(dist,dist+250,1e9);
    dist[s]=0;
    minheap<tuple<int,int>> mhp;
    mhp.emplace(0,s);
    while(!mhp.empty()) {
        int v,c; tie(c,v)=mhp.top(); mhp.pop();
        if(c>dist[v]) continue;
        int eid=0;
        for(auto &e:adj[v]) {
            int u,rev,cp,cs;
            tie(u,cp,cs,rev)=e;
            if(cp>0) {
                if(dist[u]+h[u]>cs+dist[v]+h[v]) {
                    _prev[u]={v,eid};
                    mhp.emplace(dist[u]=dist[v]+h[v]+cs-h[u],u);
                }
            }
            eid++;
        }
    }
    for(int i=0; i<250; ++i) {
        h[i]+=dist[i];
    }
    for(int v=t; v!=s; v=_prev[v].fir) {
        int x,y; tie(x,y)=_prev[v];
        get<1>(adj[x][y])--;
        get<1>(adj[v][get<3>(adj[x][y])])++;
    }
    return h[t];
}

int mincostflow(int s,int t,int f) {
    int ret=0;
    for(int i=0; i<f; ++i) {
        ret+=findway(s,t);
    }
    return ret;
}


int row(int x) {
    return 2+x;
}

int col(int x) {
    return n+2+x;
}

signed main() {
    #ifdef LOCAL
    freopen("stdout.txt","wt",stdout);
    #endif
    cin>>n;
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            cin>>w[i][j];
        }
    }
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            cin>>e[i][j];
        }
    }
    for(int i=0; i<n; ++i) {
        cin>>f[i];
        for(int j=0; j<n; ++j) {
            int &c=cost[i][j];
            for(int k=0; k<n; ++k) {
                if(k!=j) {
                    if(f[i][k]!='.') {
                        c+=e[i][k];
                        ope[i][j].emplace_back(i+1,k+1,"erase");
                    }
                } else {
                    if(f[i][k]!='o') {
                        c+=w[i][k];
                        ope[i][j].emplace_back(i+1,k+1,"write");
                    }
                }
            }
            add_edge(row(i),col(j),1,c);
        }
    }
    int s=0,t=1;
    for(int i=0; i<n; ++i) {
        add_edge(s,row(i),1,0);
        add_edge(col(i),t,1,0);
    } 
    int mcos=mincostflow(s,t,n);
    cout<<mcos<<"\n";
    vector<tuple<int,int,string>> ans;
    for(int i=0; i<n; ++i) {
        for(auto &e:adj[row(i)]) {
            int j,cap;
            tie(j,cap,ignore,ignore)=e;
            j-=n+2;
            if(cap==0) {
                for(auto &x:ope[i][j]) {
                    ans.emplace_back(x);
                }
                break;
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto &e:ans) {
        int p,q; string r;
        tie(p,q,r)=e;
        cout<<p<<" "<<q<<" "<<r<<"\n";
    }
}


Measured memory_bytes: 21408