#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define MAX_V 222

typedef pair<int,int> P;
struct edge{
  int to,cap,cost,rev;
};

int V;
vector<edge> g[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<MAX_V;i++){
    g[i].clear();
  }
}

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

int min_cost_flow(int s,int t,int f){
  int res=0;
  memset(h,0,sizeof(h));
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(que.size()){
      P p=que.top(); que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<g[v].size();i++){
        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];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }
    if(dist[t]==INF)return -1;
    for(int v=0;v<V;v++) h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
  }
  return res;
}

int n;
int w[111][111],e[111][111];
string s[111];

int main(){
	cin.sync_with_stdio(false);
  cin>>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>>s[i];
  init(2*n+2);
  rep(i,n)rep(j,n){
    int cost=s[i][j]=='o'?0:w[i][j];
    rep(k,n){
      if(i==k)continue;
      if(s[k][j]=='o'){
        cost+=e[k][j];
      }
    }
    add_edge(i,j+n,1,cost);
  }
  rep(i,n){
    add_edge(2*n,i,1,0);
    add_edge(i+n,2*n+1,1,0);
  }
  cout<<min_cost_flow(2*n,2*n+1,n)<<endl;
  vector<P> ps;
  rep(i,n){
    rep(j,g[i].size()){
      if(g[i][j].cap==0){
        ps.push_back(P(i,g[i][j].to-n));
      }
    }
  }
  set<string> qs;
  rep(l,ps.size()){
    int i=ps[l].fi,j=ps[l].se;
    if(s[i][j]=='.'){
      string tmp=to_string(i+1)+" "+to_string(j+1)+" write";
      qs.insert(tmp);
    }
    rep(k,n){
      if(i==k)continue;
      if(s[k][j]=='o'){
        string tmp=to_string(k+1)+" "+to_string(j+1)+" erase";
        qs.insert(tmp);
      }
    }
    rep(k,n){
      if(j==k)continue;
      if(s[i][k]=='o'){
        string tmp=to_string(i+1)+" "+to_string(k+1)+" erase";
        qs.insert(tmp);
      }
    }
  }
  cout<<qs.size()<<endl;
  for(string ss : qs){
    cout<<ss<<endl;
  }
	return 0;
}