#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


class CFlow{
public:
    struct edge{
        ll to;
        ll cap;
        ll rev;
        ll cost;
    };
    
    struct node{
        ll cost;
        ll flow;
        ll number;
        ll from;
        ll edge;
        
        //cost::smaller flow::bigger
        bool operator < (const node &a) const {
            if(a.cost<this->cost){return true;}
            else if(a.cost==this->cost && a.flow>this->flow){return true;}
            return false;
        }
    };
    
    ll INF;
    ll v;
    vector<vector<edge>> e;
    

    CFlow(ll v):v(v){
        e.resize(v);
        INF=1e18+7;
    }
    
    void add_edge(ll from,ll to,ll cap,ll cost){
        e[from].push_back((edge){to,cap,(ll)e[to].size(),cost});
        e[to].push_back((edge){from,0,(ll)e[from].size()-1,-1*cost});
    }
    
    pll min_cost(ll s,ll t,ll flow){
        ll cost=0;
        ll D=flow;
        vector<ll> h(v,0);
        while(flow>0){
            priority_queue<node> q;
            vector<node> V(v,{INF,0,-1,-1,-1});
            V[s]={0,flow,s,s,-1};
            q.push({0,flow,s,s,-1});
            while(!q.empty()){
                node N=q.top(); q.pop();
                ll w=N.number;
                if(N<V[w]){continue;}
                for(int i=0;i<e[w].size();i++){
                    edge &E=e[w][i];
                    node New={V[w].cost+E.cost+h[w]-h[E.to],min(N.flow,E.cap),E.to,w,i};
                    if(E.cap>0 && V[E.to]<New){
                        V[E.to]=New;
                        q.push(New);
                    }
                }
            }
            if(V[t].flow==0){break;}
            for(int i=0;i<v;i++){h[i]+=V[i].cost;}
            flow-=V[t].flow;
            ll w=t;
            while(w!=s){
                ll to=w;
                w=V[w].from;
                edge &E=e[w][V[to].edge];
                E.cap-=V[t].flow;
                e[E.to][E.rev].cap+=V[t].flow;
                cost+=V[t].flow*E.cost;
            }
            if(flow==0){break;}
        }
        return {D-flow,cost};
    }
};



    
int main(){
    ll n;
    cin>>n;
    vector<vector<ll>> w(n,vector<ll>(n));
    vector<vector<ll>> e(n,vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){cin>>w[i][t];}
    }
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){cin>>e[i][t];}
    }
    vector<string> o(n);
    for(int i=0;i<n;i++){cin>>o[i];}
    CFlow F(2*n+10);
    ll g=2*n+9;
    ll s=g-1;
    for(int i=0;i<n;i++){
        F.add_edge(s,i,1,0);
        F.add_edge(i+n,g,1,0);
    }
    vector<ll> R(n,0);
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            if(o[i][t]=='o'){R[i]+=e[i][t];}
        }
    }
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            if(o[i][t]=='o'){
                F.add_edge(i,n+t,1,R[i]-e[i][t]);
            }
            else{
                F.add_edge(i,n+t,1,R[i]+w[i][t]);
            }
        }
    }
    cout<<F.min_cost(s,g,n).S<<endl;
    vector<pll> ans;
    ll count=0;
    for(int i=0;i<n;i++){
        for(int t=1;t<=n;t++){
            if(F.e[i][t].cap==0){
                ans.push_back({i,F.e[i][t].to-n});
            }
        }
    }
    for(int i=0;i<n;i++){
        if(o[ans[i].F][ans[i].S]=='.'){count++;}
        for(int t=0;t<n;t++){
            if(t==ans[i].S){continue;}
            if(o[ans[i].F][t]=='o'){count++;}
        }
    }
    cout<<count<<endl;
    for(int i=0;i<n;i++){
        //cout<<ans[i].F<<" "<<ans[i].S<<endl;
        if(o[ans[i].F][ans[i].S]=='.'){
            cout<<ans[i].F+1<<" "<<ans[i].S+1<<" write"<<endl;
        }
        for(int t=0;t<n;t++){
            if(t==ans[i].S){continue;}
            if(o[ans[i].F][t]=='o'){
                cout<<ans[i].F+1<<" "<<t+1<<" erase"<<endl;
            }
        }
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3996